Skip to content

Add return type hints #697

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

Merged
merged 8 commits into from
Apr 9, 2025
Merged

Add return type hints #697

merged 8 commits into from
Apr 9, 2025

Conversation

Vipitis
Copy link
Contributor

@Vipitis Vipitis commented Mar 30, 2025

closes #696

found where the type hints can be added in codegen, had to work through a bunch of edge cases. Will see if these cases can be added to already existing utils.
also not sure if -> None is really wanted everywhere.

still in progress... hopefully I can get this done early next week.

as for the 2nd question in the issue, I looked through some ideas with stub classes in mypy, .pyi files and even using if "TYPE_CHECKING" to import the autobackend. But doesn't feel like that solves the issue if having the "go to declaration" button go to the implementation - I might keep this an option issue.

@almarklein
Copy link
Member

also not sure if -> None is really wanted everywhere.

Normally I'd say don't bother, but for an API like this I like the explicitness.

@Vipitis Vipitis marked this pull request as ready for review April 7, 2025 22:48
@Vipitis Vipitis requested a review from Korijn as a code owner April 7, 2025 22:48
@Vipitis
Copy link
Contributor Author

Vipitis commented Apr 7, 2025

I think this should be good mostly. please have a look as some of the edge cases feel hacky as usual.
For the request_adapter_ functions I added the return type manually due to @apidiff.change.

Will look into adding typing for properties/attributes (I think also the args to some of the constructors like GPUDevice) in a different PR to finally get the type for device.queue

Copy link
Member

@almarklein almarklein left a comment

Choose a reason for hiding this comment

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

Nice work!

@Korijn
Copy link
Collaborator

Korijn commented Apr 8, 2025

There are merge conflicts !

@Vipitis
Copy link
Contributor Author

Vipitis commented Apr 8, 2025

ah, got to rebase and likely rerun codegen. But will probably only get to that later today

@almarklein almarklein enabled auto-merge (squash) April 9, 2025 11:10
@almarklein almarklein merged commit 331d013 into pygfx:main Apr 9, 2025
20 checks passed
@Vipitis Vipitis deleted the return-type branch April 9, 2025 11:15
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.

return type hints in _classes.py and _api.py ?
3 participants