Skip to content

return type hints in _classes.py and _api.py ? #696

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

Closed
Vipitis opened this issue Mar 27, 2025 · 1 comment · Fixed by #697
Closed

return type hints in _classes.py and _api.py ? #696

Vipitis opened this issue Mar 27, 2025 · 1 comment · Fixed by #697

Comments

@Vipitis
Copy link
Contributor

Vipitis commented Mar 27, 2025

Hey, something that has bothered me for a while now:

Some of the functions that return a different object, such as GPUDevice.create_command_encoder() returns a GPUCommandEncoder. So is there any issue with providing this type annotation in general? I only played around with a few manual examples. (I can look into code gen improvements to add that, time permitting).
The main point being that in the editor I am always worried about white text for methods. And I also can't easily jump to the definition to check the arguments needed... lot's of ctrl+F
I have been using the following pattern

encoder: wgpu.GPUCommandEncoder = device.create_command_encoder()

which gives me the unimplemented function in _classes.py which as least as a docstring and the args. But getting to the actual version in wgpu_native/_api.py would be even more helpful.

So more like a question to the other devs, do you have a editor based solution or some other trick?

@almarklein
Copy link
Member

Personally, I often work in an interactive environment (Pyzo), and I would simply create the encoder so its a life object that the IDE can then inspect. Or I 'enter' a running program with a well-placed breakpoint() call and inspect from there.

That said, support for static analysis can indeed be improved. We do have annotations for arguments for a while, but return types have not been implemented yet. It would be great if we did!

I'm not sure what we can do to make it easier to jump to the implementation in wgpu_native/_api.py. I just type e.g. def create_xx in the VSCode search panel.

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 a pull request may close this issue.

2 participants