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

Run mypy for tools/wptrunner/ (but still allow untyped defs) #28942

Merged
merged 1 commit into from May 25, 2021

Conversation

foolip
Copy link
Member

@foolip foolip commented May 10, 2021

Make ConfigDict a Dict[str, Any] since the keys come from
parser.options() which are strings in typeshed:
https://github.com/python/typeshed/blob/7a9b4f93baa03fff3ef7f319988cea2cbb6e2135/stdlib/configparser.pyi#L105

Also s/SafeConfigParser/ConfigParser/ since SafeConfigParser is now a
legacy alias not mentioned in Python 3 documentation.

Part of #28833.

@@ -65,7 +65,6 @@ def env_options():


class EdgeBrowser(Browser):
used_ports = set()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

@@ -41,8 +41,6 @@ def env_options():
return {"supports_debugger": False}

class InternetExplorerBrowser(Browser):
used_ports = set()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

Base automatically changed from foolip/mypy-tools to master May 11, 2021 08:30
@foolip foolip force-pushed the foolip/mypy-wptrunner branch 6 times, most recently from eac123b to e6994a6 Compare May 17, 2021 14:24
@foolip foolip marked this pull request as ready for review May 17, 2021 14:28
@wpt-pr-bot wpt-pr-bot added infra mypy.ini wptrunner The automated test runner, commonly called through ./wpt run labels May 17, 2021
@wpt-pr-bot wpt-pr-bot requested a review from jgraham May 17, 2021 14:28
@foolip
Copy link
Member Author

foolip commented May 17, 2021

@jgraham this isn't 100% done, but it's pretty big and was the hardest mypy PR so far, so sending it for review instead of continuing to polish. If there are parts you think can be split out for clarity, I'm happy to do that.

@foolip
Copy link
Member Author

foolip commented May 17, 2021

OK, I've made some additional changes so that I'm now happy enough with this myself. Ready for proper review.

Copy link
Contributor

@jgraham jgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So generally I think I"m happy with this but I've also bitrotted you, so it's going to need an update.

Make ConfigDict a Dict[str, Any] since the keys come from
parser.options() which are strings in typeshed:
https://github.com/python/typeshed/blob/7a9b4f93baa03fff3ef7f319988cea2cbb6e2135/stdlib/configparser.pyi#L105

Also s/SafeConfigParser/ConfigParser/ since SafeConfigParser is now a
legacy alias not mentioned in Python 3 documentation.

Part of #28833.
@@ -710,7 +720,7 @@ def after_connect(self):


class WdspecProtocol(Protocol):
server_cls = None
server_cls = None # type: ClassVar[Optional[Type[WebDriverServer]]]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional is needed here because of this code added a few days ago:

class GeckoDriverProtocol(WdspecProtocol):
server_cls = None # To avoid circular imports we set this at runtime

I didn't add a comment referring to GeckoDriverProtocol because it seems guaranteed to go stale, but that's the reason if someone comes looking at this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a design problem. #29089 will address that once it's ready.

@foolip
Copy link
Member Author

foolip commented May 24, 2021

@jgraham rebased to adapt to recent changes, which was mostly throwing away changes no longer needed. I've looked over the full set of changes and it's hard to be confident every single one of them is now needed, but it's not very far from minimal I think.

When this is merged I'll revisit #28935 too.


here = os.path.dirname(__file__)

class ConfigDict(dict):
class ConfigDict(Dict[str, Any]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels weird, but I guess it's right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean it's weird to use a type as the base class? I agree, things don't work quite as I first guessed with inheritance. It's not possible to do dict: Dict[str, Any], that's a syntax error. My guess is since that aside from ABCs and maybe generics (if Python has those) inheritance is from a specific type, not a type in the mypy sense.

And typing.Dict can be used like this, by some magic I haven't inspected closely.

@@ -710,7 +720,7 @@ def after_connect(self):


class WdspecProtocol(Protocol):
server_cls = None
server_cls = None # type: ClassVar[Optional[Type[WebDriverServer]]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a design problem. #29089 will address that once it's ready.

@@ -588,7 +598,7 @@ def get_screenshot_list(self, node, viewport_size, dpi, page_ranges):

class WdspecExecutor(TestExecutor):
convert_result = pytest_result_converter
protocol_cls = None
protocol_cls = None # type: ClassVar[Type[Protocol]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've probably forgotten something but why aren't we using protocol_cls: ClassVar[Type[Protocol]] = None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would have to use Optional to allow that. For class variables, for some reason the rules are different when using the comment syntax. I can't find the docs for it now, but you can try it and see :)

@foolip foolip merged commit a5e1bc0 into master May 25, 2021
@foolip foolip deleted the foolip/mypy-wptrunner branch May 25, 2021 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infra mypy.ini wptrunner The automated test runner, commonly called through ./wpt run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants