-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update pkg_resources-stubs for use in pytype_test #9747
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
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This comment has been minimized.
This comment has been minimized.
@overload | ||
def get_distribution(dist: _D) -> _D: ... | ||
@overload | ||
def get_distribution(dist: _PkgReqType) -> DistInfoDistribution: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls get_provider()
, which according to our stub below returns a Distribution
, not a DistInfoDistribution
. I haven't traced the code to verify which is right, but we should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. Didn't look too far into it but might depend on if the distribution was .egg
, .egg-info
or .dist-info
PKG_INFO: str | ||
PKG_INFO: ClassVar[str] | ||
# Initialized to None, but is not meant to be instantiated directly | ||
egg_info: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this attribute at all (on setuptools 67.3.1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it, it's in NullProvider
. If you provide no metadata to Distribution, it uses EmptyProvider
which is a NullProvider
>>> type(pkg_resources.get_distribution("numpy")._provider)
<class 'pkg_resources.PathMetadata'>
>>> type(Distribution()._provider)
<class 'pkg_resources.EmptyProvider'>
>>> type(get_provider("numpy"))
<class 'pkg_resources.DefaultProvider'>
PathMetadata
, EmptyProvider
and DefaultProvider
all have NullProvider
in common
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
||
class EggMetadata(ZipProvider, IResourceProvider): | ||
loader: types._LoaderProtocol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comes from the zipimporter
argument to __init__
so the types should match.
egg_name: str | None | ||
egg_info: str | None | ||
loader: types._LoaderProtocol | None | ||
module_path: str | None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module_path: str | None | |
module_path: str |
The initializer unconditionally sets it to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EmptyProvider sets it explicitely to None and overrides __init__
Should I keep module_path: str | None
for sublcassing. Or add # type: ignore[assignment]
to EmptyProvider.module_path
?
Especially considering this comment: #9747 (comment)
This comment has been minimized.
This comment has been minimized.
…peshed into pytype_test-type-error
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Fixes a type issue in pytype_test. https://github.com/python/typeshed/blob/main/tests/pytype_test.py#L158
Unfortunately I can't immediately remove the
type: ignore
comment because typeshed's tests depend ontypes-setuptools
.