-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
importlib.metadata.PackageMetadata
has no get
method?
#7767
Comments
The current mypy plus typeshed plus the Python 3.10 core library has a bug causing mypy to not think get is a valid method on the return value of importlib.metadata.metadata because it returns a Protocol that doesn't implement get. I've filed a issue in case this is not intended (python/typeshed#7767), but we know that any package created by this template will always have Summary and Version metadata, so we can use them unconditionally. Previously, this may not have worked in situations where the package was being used uninstalled, but since we now do everything including local development servers from inside tox, and make init also installs the package for running pytest directly, this should no longer be an issue. setuptools_scm should always generate a version, even if it's an unuseful one.
In the latest mypy (0.942), importlib.metadata.metadata now returns a Protocol named PackageMetadata that doesn't implement the get method. The actual object remains a Message class, however, so the get method works correctly. Only mypy checking fails. Pending python/typeshed#7767, which may reveal that it is intentional that get not be supported, cast the return value to Message so that the existing functions work. This seems better than adding try/catch blocks for every piece of metadata of interest given that the omission of get appears to be unintentional.
I ran into this problem too. |
I don't think this is a question that we, at typeshed, can really answer. We're basically taking the type hints from upstream here, and I think — since |
get
method for PackageMetadata
importlib.metadata.PackageMetadata
has no get
method?
Yeah, sorry for the weird phrasing there — I meant that the question is more "is there supposed to be a .get() method?" as opposed to "why did typeshed leave out the .get() method?" As you pointed out, that question is better answered by the importlib_metadata folks. I'll open an issue over there asking about it. 🙂 |
Opened python/importlib_metadata#384 asking for a clarification on whether it's an implementation detail that should be migrated away from. |
Thank you! |
I'm marking this issue as "deferred" until we get an answer from upstream |
There's some more details in python/importlib_metadata#384 (comment) , but I'll quote the part that seems directly-relevant here:
The rest of the comment mentions possibly adding it, but right now typeshed is correct. |
I don't think there's anything actionable for typeshed here unless and until the runtime decides that |
* ⬆️ UPGRADE: Autoupdate pre-commit config * 🔧🧹 Removed interrogate pre-push hook * 🩹📚 Fixed typo * 🔧👌 Sorted pre-commit hooks to run more effectively * 🔧🩹 Fixed rstcheck hook config * 🔧🧹 Ignore false positive type error Ref.: python/typeshed#7767 Co-authored-by: s-weigand <s-weigand@users.noreply.github.com>
Since the return value for
importlib.metadata.metadata
was fixed in #7331, mypy now incorrectly diagnoses calls toget
as a call to an invalid method. That PR took the approach of importingPackageMetadata
from the relevant module, but that protocol does not apparently capture the entire supported interface.(Maybe this is a bug in my understanding of the return value of metadata and
get
isn't a valid call? But I have a lot of code that does this and it's always worked.)The text was updated successfully, but these errors were encountered: