Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide typing.Protocol for dash_duo #2170

Open
janosh opened this issue Jul 27, 2022 · 5 comments
Open

provide typing.Protocol for dash_duo #2170

janosh opened this issue Jul 27, 2022 · 5 comments
Labels
feature something new P3 not needed for current cycle

Comments

@janosh
Copy link

janosh commented Jul 27, 2022

Is your feature request related to a problem? Please describe.

The DX for using the pytest fixture dash.testing.plugin.dash_duo() could be improved by providing a typing.Protocol to type hint available methods and their signatures.

Describe the solution you'd like

from typing import Protocol

import dash
from dash.testing.application_runners import import_app
from dash.testing.wait import wait_for_element_by_css_selector, wait_for_text_to_equal


class DashDuo(Protocol):
    "The dash_duo pytest fixture lives in dash.testing.plugin.dash_duo."

    def start_server(self, start_server) -> None:
        ...

    def find_element(self, selector: str) -> dash.development.base_component.Component:
        ...


def test_example_app(dash_duo: DashDuo):  # type hint for dash_duo enables auto-complete
    app = import_app("example")
    dash_duo.start_server(app)

    my_component = dash_duo.find_element("#hello-world")

    assert "my-value" == my_component.get_attribute("value")

    ....

Screenshot from VS Code showing auto-complete in action

Screen Shot 2022-07-27 at 11 11 43

Describe alternatives you've considered

None

@alexcjohnson
Copy link
Collaborator

Seems reasonable, @T4rk1n you've worked on typing for dash.testing a bit, any thoughts? Will it be possible to have this picked up automatically by VSCode when dash_duo is used as a pytest fixture, or will you still need to import a DashDuo and annotate every dash_duo?

@janosh
Copy link
Author

janosh commented Aug 1, 2022

You would have to annotate every single use of dash_duo unless you had some extension like pytest-fixtures installed.

@T4rk1n
Copy link
Contributor

T4rk1n commented Aug 1, 2022

Pycharm pick it up by default, not a vscode user so I don't know about it, but seems like the plugin would work?

@janosh
Copy link
Author

janosh commented Aug 1, 2022

I made a rough start over here if you want to pick up from that. Or maybe DashDuo can be auto-generated?

@kostyafarber
Copy link

Hi this sounds interesting. Happy to pick it up with some guidance. Thanks.

@gvwilson gvwilson self-assigned this Jul 24, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P3 not needed for current cycle feature something new labels Aug 13, 2024
@gvwilson gvwilson changed the title [Feature Request] typing.Protocol for dash_duo provide typing.Protocol for dash_duo Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 not needed for current cycle
Projects
None yet
Development

No branches or pull requests

5 participants