Skip to content

importlib.metadata.PackageMetadata has no get method? #7767

@rra

Description

@rra

Since the return value for importlib.metadata.metadata was fixed in #7331, mypy now incorrectly diagnoses calls to get as a call to an invalid method. That PR took the approach of importing PackageMetadata 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.)

% cat test.py
from importlib.metadata import metadata
print(metadata("mypy").get("Version"))
% python test.py
0.950
% mypy test.py
test.py:2: error: "PackageMetadata" has no attribute "get"
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: deferredIssue or PR deferred until some precondition is fixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions