Skip to content

Add return type hints#697

Merged
almarklein merged 8 commits into
pygfx:mainfrom
Vipitis:return-type
Apr 9, 2025
Merged

Add return type hints#697
almarklein merged 8 commits into
pygfx:mainfrom
Vipitis:return-type

Conversation

@Vipitis

@Vipitis Vipitis commented Mar 30, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

Vipitis commented Apr 7, 2025

Copy link
Copy Markdown
Contributor Author

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

Comment thread codegen/idlparser.py

@almarklein almarklein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work!

@Korijn

Korijn commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator

There are merge conflicts !

@Vipitis

Vipitis commented Apr 8, 2025

Copy link
Copy Markdown
Contributor Author

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
@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