[py] PEP 484 type hints for common.exceptions and webdriver.support.color#9482
Conversation
|
@AutomatedTester gentle ping (no rush though!). Please advise:
|
AutomatedTester
left a comment
There was a problem hiding this comment.
@AutomatedTester gentle ping (no rush though!). Please advise:
1. Is the PR too big for a review? I will split it if necessary and create smaller PRs in the future.
No, this is fine. Don't go much bigger than this though.
2. I would like to add a new job that runs `mypy` checks, but it will fail until all the codebase is typed and unfortunately GH actions syntax doesn't allow to ignore failing jobs. I can filter out untyped modules in `mypy` config (so no errors are reported) and loosen the filter gradually with each typed module, like suggested in [mypy docs](https://mypy.readthedocs.io/en/stable/existing_code.html): ```ini # mypy config [mypy] ... [mypy-selenium.webdriver.*] ignore_errors = True [mypy-selenium.webdriver.support.event_firing_webdriver] ignore_errors = True # etc ```
I've not used mypy in anger so I might need your help here. Is there a way that we can do a pass over and have file that holds the current output so we can't regress and then fix the others? A little similar to how Rubocop works for Ruby. If your suggestion above does that then do it and we can then clean it up as we go. Let's try not boil the ocean.
py/selenium/common/exceptions.py
Outdated
| """ | ||
|
|
||
| def __init__(self, msg=None, screen=None, stacktrace=None): | ||
| def __init__(self, msg: Any = None, screen: Any = None, stacktrace: Any = None) -> None: |
There was a problem hiding this comment.
These are always going to be str or `None
py/selenium/common/exceptions.py
Outdated
| commands. | ||
| """ | ||
| def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None): | ||
| def __init__(self, msg: Any = None, screen: Any = None, stacktrace: Any = None, alert_text: Any = None) -> None: |
There was a problem hiding this comment.
The types here are str or None.
There was a problem hiding this comment.
@AutomatedTester I guess except stacktrace? Looking at this right now:
selenium/py/selenium/webdriver/remote/errorhandler.py
Lines 208 to 236 in c138008
I see what you mean - unfortunately, my suggestion doesn't do that, it's merely "hide modules with errors until those are fixed, and don't forget to uncover them back once fixed". However, |
Signed-off-by: oleg.hoefling <[email protected]>
Signed-off-by: oleg.hoefling <[email protected]>
Signed-off-by: oleg.hoefling <[email protected]>
Signed-off-by: oleg.hoefling <[email protected]>
Signed-off-by: oleg.hoefling <[email protected]>
8f331c7 to
6ed6f8a
Compare
|
Kudos, SonarCloud Quality Gate passed! |
Description
This is the initial PR that adds type hints to Python codebase. Typed modules:
selenium.common.exceptions,webdriver.support.color.I have selected those two for the initial typing since they do not depend on any other modules and can be typed in isolation.
Motivation and Context
The goal of this PR is to configure and add initial integration for the
mypytool (checks the type hints validity). It can be run viaor
Right now it emits 1248 errors, mainly due to missing type hints; the goal is to gradually reduce it to zero. No errors are emitted in modules typed in this PR.
Types of changes
Checklist