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 full repo & fix all mypy issues #227

Merged
merged 74 commits into from
Mar 23, 2024
Merged

Conversation

fohrloop
Copy link
Owner

@fohrloop fohrloop commented Mar 23, 2024

Mypy

Previously, mypy was only ran for ./wakepy folder. But there seems some added value in running static type checking also for tests, since it also shows how different parts of wakepy look like when running mypy on a project that uses wakepy. I found at least places which were not so user friendly for people using wakepy, and fixed them. I also fixed 80+ mypy errors.

StrEnums and their values

Each subclass of StrEnum has not corresponding Values class. For example PlatformName has PlatformNameValues which is a typing.Literal. This is to allow giving the literal values (strings) as function arguments, when a function expects value listed in StrEnum. The StrEnum and the corresponding Values are enforced to be in sync with a unit test.

StrEnum class is now simplified a bit.

do_assert

added a do_assert helper for tests which can be used in place of assert statement if you're getting [unreachable] errors with mypy.

Other

Mode.activation_result is now ActivationResult (was: ActivationResult | None). This makes it easier to work with the object when using wakepy and mypy in a project.

Method.name is now always a string. Unnamed methods have special name "unnamed". This makes working with wakepy+mypy easier. There is also now Method._is_unnamed() which can be used to check if the Method has a name.

fohrloop added 30 commits March 14, 2024 19:13
Easier to work with the function when using mypy
Needed for == operation with StrEnum members
The __eq__ and __hash__ were not required after all.
there is probably no real use case for that and not supporting None makes the type
annotations of the function easier
The 'self' refers to a class so perhaps clearer the the variable name is 'cls'
was: ConstantEnumMeta (previously, StrEnum was called Constant)
There was old information.
fohrloop added 28 commits March 18, 2024 21:26
* these parts are unreachable, and that is known. Just testing that they're
  really are unreachable
Use module level Counter instead of function-level attribute dict
Less places where we have to check for python version, and
less places where a custom '# pragma: ' is required
- Added new rules: no-cover-if-py-gte-38 and no-cover-if-py-lt-38
@fohrloop fohrloop merged commit 5eb9212 into dev Mar 23, 2024
7 checks passed
@fohrloop fohrloop deleted the use-mypy-in-tests branch March 23, 2024 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant