selenium: [🐛 Bug]: [py] Many type annotation errors need fixing

Description

TLDR: Our use of type hints in the Python bindings needs some serious love.


Static typing is optional in Python, and we make use of it in many places throughout the Python bindings code. Static typing is not enforced at runtime, but can be checked with tooling like Mypy.

We currently have a Mypy environment and set of type checking rules declared in our tox.ini configuration. You can run Mypy locally with:

tox -e py/tox.ini -e mypy

Running this produces a screen full of type errors and:

Found 120 errors in 30 files (checked 114 source files)

We currently run Mypy in a CI workflow, but we don’t display the errors or fail the job when it hits errors, so they just go unnoticed.

To resolve this issue, we should:

  • go through the codebase and fix all of the errors that Mypy finds
  • update the CI job to fail when Mypy encounters errors to enforce no future regressions

Reproducible Code

tox -e py/tox.ini -e mypy

Debugging Logs

Found 120 errors in 30 files (checked 114 source files)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 25 (19 by maintainers)

Most upvoted comments

I’m not sure who is working on this, but I addressed some of these in #15784

I will merge that soon, so please update your local branches once it lands and continue working from there.

Hi @Bradltr95, Thanks for asking.

I’m not familiar with the organization’s rules yet, but I’m working on it. I’ve already fixed some issues. If you can give me a couple of days to upload my progress, then you can continue from there. That would be great.

@MohabASHRAF-byte I didn’t get your Slack message. I think I have 2 different accounts there with the same username. Try the other one 😃

@MohabASHRAF-byte thanks! Not only are there many Mypy errors, but many of the type annotations are using outdated classes and syntax. An easy way to update them is by using this:

https://github.com/asottile/pyupgrade

Run it across the whole codebase using Python 3.9 syntax.

Ping me here or on Slack if you have any questions.

@MohabASHRAF-byte Yes, we use slack, you can join here - https://inviter.co/seleniumhq

@MohabASHRAF-byte yes, go ahead. We appreciate contributions from your side.