Skip to content
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

Add casts for package metadata #99

Merged
merged 2 commits into from
May 2, 2022
Merged

Add casts for package metadata #99

merged 2 commits into from
May 2, 2022

Conversation

rra
Copy link
Member

@rra rra commented May 2, 2022

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.

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.
@rra rra requested a review from jonathansick May 2, 2022 18:34
mypy also complains when casting the return value of metadata to
Message on older versions where that's the default return value,
so make the cast conditional on the Python version.
@rra rra merged commit 9cfa0f9 into master May 2, 2022
@rra rra deleted the u/rra/upgrades branch May 2, 2022 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants