-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Distribute and install py.typed to provide type information #9279
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
Conversation
pip does not support being imported directly. You can do it, but it’s not supported. I’m -1 unless |
Thanks for taking the time to respond. I understand pip's policy and I agree with it continuing. However, in this case, including The facts remain:
At some point, there will be the need for pip-adjacent features that are out of scope to be implemented in pip. Right now, pip-tools fills one of those roles. pip-tools isn't asking for any API stability, just a hand by providing PEP-561 compatible type information. As the inclusion is only a single empty file, would you reconsider? Thanks. |
I don't think we're in any way concerned about including an empty file, but rather about what it indicates. ;) None the less, I think adding this in for pip-tools is OK -- I'm a little worried that some folks might take this as an indicator for probing into pip's internals, but we got https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program for that. :) |
FWIW, you'll need to rebase this PR on the current |
Can we add content to |
Done.
In that case, shall I exclude the changelog note so as not to draw attention to it? |
@uranusjr That is a good idea! I'll look into it. |
Yea, that'd work. |
For the record, I agree with @pradyunsg - it's more what having this file implies that bothers me. I don't know enough about mypy to know why having an empty file with that name present makes such a difference, or why pip-tools can't get the same effect (which I presume is to do with taking account of the type annotations in pip?) by any other means, so I'm relying on other people's judgement over that point. |
@pfmoore Quoting from the PEP linked in OP:
Basically, it indicates to mypy that it can use type annotations in-source on the project, rather than looking for them in |
That's what I gather. And it's impossible for pip-tools to tell mypy that it should use the annotations present in pip's code base unless pip adds that file? That sounds surprisingly strict to me - in the spirit of "consenting adults", I'd have expected a way to do this without needing explicit permission. And it's not possible for pip-tools to temporarily add that file to their copy of pip when type checking? I guess the answer is that this just makes it more convenient for pip-tools, rather than there being no possible other way of doing it. But that comes back to whether we want to make it convenient for people to use pip's internals, even popular and important projects like pip-tools... Ultimately, though, I don't feel strongly enough to object, as long as it's clear to everyone that it doesn't imply any sort of commitment on pip's part. |
After some experimenting, I have confirmed that the contents of So, the file now contains wording to emphasize that pip types and API are not stable. Suggestions on the wording are most welcome. All other review feedback has also been included in the latest revision. I'm not sure why my |
I've labelled the PR as trivial so you don't need the |
Complies with PEP 561: https://www.python.org/dev/peps/pep-0561/#packaging-type-information By distributing and installing the py.typed file, mypy will use pip's type information when imported into other projects. For example, the pip-tools project can use pip's types and mypy to help verify correctness. mypy docs: https://mypy.readthedocs.io/en/stable/installed_packages.html#making-pep-561-compatible-packages
Thanks. Dropped the news file. |
There's a bug in the pypa-bot, that I've not been able to identify yet. :( |
...
pip-tools recently started running mypy: jazzband/pip-tools#1275 Like pip itself, the project is using a pre-commit hook to run mypy. As far as I know, pre-commit can't be easily configured to run arbitrary commands prior to the hook (e.g. So ultimately, it could workaround this, but it would be cumbersome and inconvenient. I consider that a last resort option for the pip-tools project. |
I think it is a worthwhile discussion whether a downstream package should be able to say this library does not contain a |
Perhaps python/mypy#8545 and python/mypy#8512 cover your suggestion? |
pip-tools has been adding more type hints lately: jazzband/pip-tools@d9f50f1 Any thoughts on reconsidering this to help it out? |
I'm on board for adding this. Worst case, it's gonna be helpful to someone accessing |
Nobody seems to really object. |
Complies with PEP 561:
https://www.python.org/dev/peps/pep-0561/#packaging-type-information
By distributing and installing the py.typed file, mypy will use pip's
type information when imported into other projects. For example, the
pip-tools project can use pip's types and mypy to help verify
correctness.
mypy docs:
https://mypy.readthedocs.io/en/stable/installed_packages.html#making-pep-561-compatible-packages