Allow types-foo to depend on foo#159
Conversation
|
I don't think type checkers will resolve this correctly. |
Why do you think that? From type-checkers' PoV, setuptools and pkg_resources are two different packages. And all tests in python/typeshed#13369 (where setuptools needs pkg_resources) pass. Test file: from setuptools import setup
import pkg_resources
from typing_extensions import reveal_type
reveal_type(pkg_resources.Requirement)
setup()w/o with with |
…ader into Allow-self-dependency
| if ( | ||
| runtime_req_name != upstream_distribution # Allow `types-foo` to require `foo` | ||
| and not runtime_in_upstream_requires(req, data) | ||
| and not runtime_in_upstream_sdist_requires(req, data) | ||
| ): |
There was a problem hiding this comment.
Alternative syntax:
| if ( | |
| runtime_req_name != upstream_distribution # Allow `types-foo` to require `foo` | |
| and not runtime_in_upstream_requires(req, data) | |
| and not runtime_in_upstream_sdist_requires(req, data) | |
| ): | |
| if not ( | |
| runtime_req_name == upstream_distribution # Allow `types-foo` to require `foo` | |
| or runtime_in_upstream_requires(req, data) | |
| or runtime_in_upstream_sdist_requires(req, data) | |
| ): |
| req, data | ||
| ) and not runtime_in_upstream_sdist_requires(req, data): | ||
| if ( | ||
| runtime_req_name != upstream_distribution # Allow `types-foo` to require `foo` |
There was a problem hiding this comment.
if you want me to hide this check behind a function for consistency, I'd call it runtime_is_upstream.
| req, data | ||
| ) and not runtime_in_upstream_sdist_requires(req, data): | ||
| if ( | ||
| runtime_req_name != upstream_distribution # Allow `types-foo` to require `foo` |
There was a problem hiding this comment.
I think this is the bug that I alluded to when I wrote the refactoring PR. But wouldn't it be clearer to just check req.name == upstream_distribution at the beginning of the function and exit early? This would also skip fetching the data from PyPI.
There was a problem hiding this comment.
But wouldn't it be clearer to just check
req.name == upstream_distributionat the beginning of the function and exit early? This would also skip fetching the data from PyPI.
If we don't mind not validating that upstream_distribution does exist on pypi in this case.
Of course for any existing stubs on typeshed we'd assume that its upstream does exist on pypi.
But let's say someone adds a new stubs, mistyped the distribution's name, and makes it reference on itself. It's quite the edge case, but to be considered.
Hmm, I guess stubtest and maybe other tools as well would fail. So probably fine.
There was a problem hiding this comment.
I think this is the bug that I alluded to when I wrote the refactoring PR. But wouldn't it be clearer to just check
req.name == upstream_distribution
I'm not sure which side the the EXTERNAL_RUNTIME_REQ_MAP makes sense here. (and tbh I may be too tired rn to make sense of it ^^") But I was reusing what's in runtime_in_upstream_sdist_requires and runtime_in_upstream_requires
Edit: I think it doesn't really matter because we wouldn't self reference, let's say django-stubs, and this mapping specifically lists stubs outside typeshed. So yeah, simpler to use req.name directly.
This is relevant
setuptoolsin python/typeshed#13369 (comment) and might be relevant topywin32later as well.Relates to #90