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

Type stubs? #247

Open
vergenzt opened this issue Jan 14, 2025 · 8 comments
Open

Type stubs? #247

vergenzt opened this issue Jan 14, 2025 · 8 comments
Labels
enhancement New feature or request

Comments

@vergenzt
Copy link

Would you be open to type stubs being merged into this repo?

@vsajip
Copy link
Owner

vsajip commented Jan 14, 2025

I would prefer separate stubs, at least for now, as the package still supports Python 2.x.

@vergenzt
Copy link
Author

What if it were proposed in a separate .pyi file, leaving the existing Python-2.x-compatible code unannotated?

@vsajip
Copy link
Owner

vsajip commented Jan 16, 2025

That seems more reasonable - by all means propose a .pyi file with typing information, and I'll aim to keep that updated with any API changes. I'm not too familiar with Python typing tools - what would be a reasonable test that the typing information is complete for all APIs?

@lovetox
Copy link

lovetox commented Jan 28, 2025

https://github.com/microsoft/pyright/

and here a github action you can use https://github.com/jakebailey/pyright-action

@lovetox
Copy link

lovetox commented Jan 28, 2025

#248

I dont think there is a way to test if the API is typed. All typing tools test the whole code of the project for missing types or type errors, to my knowledge there is no way to tell it "test only public API"

@vergenzt
Copy link
Author

@lovetox yeah pyright doesn't validate that type stubs are consistent with the base untyped Python code.

There's a mypy tool that targets this use case: Automatic stub testing (stubtest) - mypy 1.14.1 documentation

And more discussion here: python/mypy#5028

I've never attempted this though, so am not yet familiar with the rough edges.

@vergenzt
Copy link
Author

https://github.com/instagram/MonkeyType looks like a tool that might also be useful!

MonkeyType uses the sys.setprofile hook provided by Python to interpose on function calls, function returns, and generator yields, and record the types of arguments / return values / yield values.

@lovetox
Copy link

lovetox commented Feb 5, 2025

I contribute the stubs to typeshed, as after discussion the maintainer dont want to ship the stubs.

See python/typeshed#13465

@vsajip vsajip added the enhancement New feature or request label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants