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

Add Python annotations to have type hints #97

Merged
merged 5 commits into from
Jun 8, 2024

Conversation

gacarrillor
Copy link
Collaborator

@gacarrillor gacarrillor commented Jun 5, 2024

Completed packages:

  • dataobjects
  • db_factory

Other packages might have been touched but not completed due to lack of time.

Some considerations:

  • A couple of args were changed to have a _ prefix, e.g., `_layer, to indicate the parameter is unused.
  • from future import annotations: Added to be able to use the class LegendGroup as a return type in LegendGroup's getitem() method.
    • --keep-runtime-typing was added to avoid that the aforementioned info enables pre-commit's pyupgrade to change Optional/Union statements by new syntax "a | b" (which wouldn't be compatible with Python < 3.10)
  • list is preferred over List.
  • tuple is preferred over Tuple.
  • Order of class declarations was altered in 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 like list[str] in old Python versions.

@gacarrillor gacarrillor force-pushed the python_annotations branch from 291aac8 to 4770867 Compare June 5, 2024 22:13
@gacarrillor gacarrillor changed the title Add Python annotations to have type hints (partial) Add Python annotations to have type hints Jun 6, 2024
Copy link
Member

@signedav signedav left a 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it?

Copy link
Collaborator Author

@gacarrillor gacarrillor Jun 7, 2024

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)).

@gacarrillor
Copy link
Collaborator Author

Supernice - Can you open an issue to note what parts still need the type hints? Do the issue here and not on QgisModelBaker repo.

Done in #99

@gacarrillor
Copy link
Collaborator Author

@signedav, what do you think about bumping Python to (at least) 3.7? See note in the description.

@signedav
Copy link
Member

signedav commented Jun 7, 2024

A yes. I wanted to ask you. Where we set this minimum requirement? On publishing to pypi?

@gacarrillor
Copy link
Collaborator Author

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

@signedav
Copy link
Member

signedav commented Jun 7, 2024

Ok lets bump 👊

@gacarrillor gacarrillor merged commit 2550ee3 into opengisch:main Jun 8, 2024
5 checks passed
@gacarrillor gacarrillor deleted the python_annotations branch June 8, 2024 01:17
@gacarrillor gacarrillor mentioned this pull request Jun 22, 2024
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.

2 participants