-
Notifications
You must be signed in to change notification settings - Fork 36
Add typing stubs #248
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
Add typing stubs #248
Conversation
.pyi and py.typed are added to the source distribution, but i did not succeed in adding it to the wheel. Without shipping those two files this MR is not useful though. I suspect this i a problem with the layout of this project, there is no proper module defined with a init.py. But thats just a guess. |
Thank you for starting on this! ❤️ |
|
Perhaps you should add them to |
@vsajip this does not change anything, adding the file to manifest.in or setup.cfg includes them correctly in the source distribution. The problem is afterwards the files are not included in the wheel.
if i now think about it, this makes sense. As you are not distributing a python package. A python package is defined as a folder with a |
i tried with a src layout and everything worked fine, this is a very common way how packages are layout today https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#using-a-src-layout |
It's a common layout nowadays, but it wasn't when this package was developed. There should be a way of doing it without forcing a |
|
As guessed, module only distributions cannot ship typing stubs see https://peps.python.org/pep-0561/
Module only distribution is a kind of legacy behavior, i don't think it has any benefits over distributing a proper package, its simply there for historic reasons. let me know if you want to migrate to a package, i dont see any impact on users (python2 or python3) by such a step. The most impact it probably has would be on some helper scripts, or CI jobs which would need to be adapted. |
I don't especially want to move to a package just to add typing - it's a one-module package, anyway. I guess perhaps it's because |
But I appreciate your efforts in this direction. Thanks! |
By the way @lovetox , I don't agree with this statement of yours:
There are many modules (not packages) both in the standard library and on PyPI. Do you have a source for your claim, or is it just your opinion? Modules (single |
What i said is my opinion from my experiences over the years. Python import resolution works in the way that it will load modules directly put into the site-package dir. This behavior will not change as far as i know. And as long as python does this, an installation frontend like pip can of course put a module there. historic was maybe not the best chosen word, its not historic as in obsolete. Its historic because almost no project today will distribute only a single module. All kind of packaging features will need a proper package (namespace packages, distributing non-py files, mark package as typed). A package is defined as a folder with an These are not two competing ways of distributing a python module, its more like, either you have the most simple project possible then you can put your module into the site-packages dir or for everything else you need to put it into a subfolder (package). Even the official tutorial distributes a single example module, and does this by using a package. https://packaging.python.org/en/latest/tutorials/packaging-projects/ Im not aware of any advantage distributing a single module vs a package. I don't think its more useful to distribute a single module vs a package. Useful for who? The user that installs via pypi? Why would they care about if your module is directly in the site-package dir or in a subfolder? For me this is simply a decision of what i want to distribute, if i want to distribute more than a .py file, i simply need to put it into a subfolder (package), there are not more considerations you would need to do. |
As I see it, there is no advantage or disadvantage between packages and modules. When a piece of software becomes too unwieldy to manage in a single source file, I make a package. Because |
The advantage is that you can distribute non-py files with a package. A typed package makes the project vastly more useful to users
And all that will hopefully lead to If you still think that users profit more from the fact that after they install In the event this does not convince you, you could still merge the |
Sure, I get that.
Sure, but I'm not especially pushing for it. I'm not against typing per se - I'm just fine with Python being dynamically typed, and this project specifically doesn't have a lot of different types and complex APIs that would really benefit from type checks - though I can see the benefits in general. So I'm not against merging the Remember, you can contribute this change and move on. I expect it will lead to more maintenance for me (for, as I see it currently, not enough benefit) which is not welcome specifically because (a) I don't generally using typing in my projects, as I'm fine with dynamic typing and (b) I'm not sure the ecosystem around typing is mature enough yet. But that is no doubt because I haven't really gotten into it, because of (a). |
There is another option. python allows it that a third party can provide stubs via a different package. The package needs to be named It would make most sense if you would create this project under your name. If you dont want to maintain it for now, i would offer to do that, you could simply add me as maintainer to this new project. EDIT: I could also contribute the stubs to https://github.com/python/typeshed which is automatically pulled in by type checkers. |
I will try to get the stubs into typeshed, i opened a PR python/typeshed#13465 If you ever come around and include stubs in this package, a simple PR in typeshed can be done to mark the stubs obsolete. So i close this PR for now. |
No description provided.