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
Conversation
@@ -65,7 +65,6 @@ def env_options(): | |||
|
|||
|
|||
class EdgeBrowser(Browser): | |||
used_ports = set() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unused.
eac123b
to
e6994a6
Compare
@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. |
e6994a6
to
044c143
Compare
OK, I've made some additional changes so that I'm now happy enough with this myself. Ready for proper review. |
There was a problem hiding this 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.
044c143
to
918f54c
Compare
@@ -710,7 +720,7 @@ def after_connect(self): | |||
|
|||
|
|||
class WdspecProtocol(Protocol): | |||
server_cls = None | |||
server_cls = None # type: ClassVar[Optional[Type[WebDriverServer]]] |
There was a problem hiding this comment.
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:
wpt/tools/wptrunner/wptrunner/executors/executormarionette.py
Lines 1100 to 1101 in c21b0b8
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.
There was a problem hiding this comment.
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.
@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]): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]]] |
There was a problem hiding this comment.
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]] |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 :)
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.