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

Stubs for zstd #9483

Closed
victorbnl opened this issue Jan 9, 2023 · 5 comments · Fixed by #9484
Closed

Stubs for zstd #9483

victorbnl opened this issue Jan 9, 2023 · 5 comments · Fixed by #9484
Labels
stubs: request OUTDATED! Request to add stubs for a new package to typeshed

Comments

@victorbnl
Copy link
Contributor

zstd is an extension library written in C for Python. I'd like to add stub files for it. However, I don't know whether I should make a pull request on their repo or add them to typeshed.

I'd like to make a PR on their repo, the issue is I don't know how to provide stub files along with the module itself. I tried to add the stub files in the src/ directory, both as zstd.pyi and __init__.pyi, then I tried to add these files to the package_data section in the setup.py file. Nonetheless, the stubs seem to get ignored in all cases; testing on a project I have which depends on zstd, I keep getting:

error: Cannot find implementation or library stub for module named "zstd"  [import]

Is it even possible to ship those .pyi directly with the package? If so, how can I do so? Or should I just add them to typeshed anyway? Thanks!

@JelleZijlstra
Copy link
Member

Sounds like you didn't add a py.typed file. See https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages for how to make an installed package compatible with mypy.

In general, we prefer if type information comes with the packages themselves, so the ideal would be for zstd itself to distribute stubs. If the zstd maintainers are unwilling to add types, however, typeshed would be happy to accept them.

@hauntsaninja
Copy link
Collaborator

Btw, https://github.com/indygreg/python-zstandard I think is a little better maintained and ships with a py.typed

@victorbnl
Copy link
Contributor Author

Thanks for the suggestion, I'll consider using it then!

As for zstd, I added a py.typed file in added it in the package_data section, and it does get added, here is for proof the extracted wheel:

image

Still when I install it and run stubtest zstd I get MISSING

@JelleZijlstra
Copy link
Member

I checked and zstd is distributed as a single .so file, which means it actually cannot be typed with a py.typed file; see python/typing#1333. The options are:

  • Turn zstd into a package (as described in the typing issue)
  • Wait for the typing issue to be resolved
  • Put stubs in typeshed

@victorbnl
Copy link
Contributor Author

As I don't know what's the developer's perspective regarding the issue and how the library is being used I wouldn't take the risk of turning it into an actual package, considering the unexpected side-effects it can have. I also don't want to wait for the issue to be fixed. I'll make the PR to add it to typeshed then. Thanks for the help!

@AlexWaygood AlexWaygood added the stubs: request OUTDATED! Request to add stubs for a new package to typeshed label Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: request OUTDATED! Request to add stubs for a new package to typeshed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants