-
Notifications
You must be signed in to change notification settings - Fork 254
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
Basic mypy support #829
Basic mypy support #829
Conversation
Hi @qarmin! Thank you for devoting some time to this 😊 The GitHub Actions pipeline is currently failing (81 unit tests are KO), so I cannot merge this for now. I investigated a little by fetching your branch on my computer.
This tells me that the line-breaking logic implemented in
It's good news that, thanks to you additions, some IDEs can perform more checks and alert users of potential errors!
That's OK 👍 |
@@ -169,7 +169,9 @@ def get_width( | |||
""" | |||
|
|||
if chars is None: | |||
chars = self.characters[start:end] | |||
chars = self.characters[start:end] # type: ignore[assignment] | |||
assert chars is not None # make mypy happy |
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.
self.characters being empty should not normally happen, but it might be reasonable to just return 0.0 as the width if it does.
FWIW, I'd recommend running mypy and pyright on the codebase in the CI, at least for the oldest supported Python version, to ensure contributors don't accidentally break the type hints. Invalid syntax and imports should mostly be covered by existing unit tests. If (and only if) the types are complete, (or at least, more complete than typeshed's) you should also ship a |
Part of #827
Checklist:
The GitHub pipeline is OK (green),
meaning that both
pylint
(static code analyzer) andblack
(code formatter) are happy with the changes of this PR.A unit test is covering the code added / modified by this PR - N/A
This PR is ready to be merged
In case of a new feature, docstrings have been added, with also some documentation in the
docs/
folder - N/AA mention of the change is present in
CHANGELOG.md
- N/A - this not changes anythingLooks that mypy may really increase usability of this library.
Only part of functions are typed and sometimes info about type is available only in docs, so IDE cannot determine if type is valid or not.
Also this will allow to remove such strange tests - now IDE automatically shows me that this arguments aren't valid
If someone wants to try implement more types, then I suggest to start with command
and if all things are fixed, then removing one by one errors from
disable_error_code
insidemypy.ini
file should be enough to add types to allI added also
swig
into CI requirements, because without it I was not able to install all requirements.txt files.