-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Python annotations to have type hints #97
Conversation
… this syntax requires Python 3.9+)
291aac8
to
4770867
Compare
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.
Supernice - Can you open an issue to note what parts still need the type hints? Do the issue here and not on QgisModelBaker repo.
@@ -41,3 +41,5 @@ repos: | |||
rev: v3.3.1 | |||
hooks: | |||
- id: pyupgrade | |||
args: | |||
- "--keep-runtime-typing" |
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.
What does it?
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.
Without it, pyupgrade changes Optional/Union statements by new syntax "a | b" (Python v3.10+), which won't be completely backwards compatible (namely, there might be issues with runtime operations like isinstance(obj, str | int)
).
Done in #99 |
@signedav, what do you think about bumping Python to (at least) 3.7? See note in the description. |
A yes. I wanted to ask you. Where we set this minimum requirement? On publishing to pypi? |
Yes, I've only seen it in setup.py |
Ok lets bump 👊 |
Completed packages:
dataobjects
db_factory
Other packages might have been touched but not completed due to lack of time.
Some considerations:
_
prefix, e.g., `_layer, to indicate the parameter is unused.from future import annotations
: Added to be able to use the classLegendGroup
as a return type inLegendGroup
'sgetitem()
method.--keep-runtime-typing
was added to avoid that the aforementioned info enables pre-commit'spyupgrade
to changeOptional
/Union
statements by new syntax "a | b" (which wouldn't be compatible with Python < 3.10)list
is preferred overList
.tuple
is preferred overTuple
.forms.py
to be able to use some of the classes (of the same module) in other classes' types.Note:
We may need to consider to bump Python to at least 3.7, since that version introduces the
from __future__ import annotations
, which makes it possible to use modern typing syntax likelist[str]
in old Python versions.