Skip to content

Improve the annotations of types.MappingProxyType #5822

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

Merged
merged 4 commits into from
Jul 30, 2021

Conversation

BvB93
Copy link
Contributor

@BvB93 BvB93 commented Jul 30, 2021

This PR improves the annotations of MappingProxyType in the following two manners:

  • It adds annotations for attributes that were previously unannotated (985e6e7).
  • It improves the annotations of a number of inherited methods (54b4b1c).

The second set of changes uses the same assumption that was made for its copy method (xref #4510):
that the underlying mapping is a dictionary.

Just as with MappingProxyType.copy this assumption is not guaranteed to always be true,
but it will result in an improvement for the majority of cases (e.g. #5808 once its return type has been fixed)

Bas van Beek added 3 commits July 30, 2021 14:19
* `__hash__`
* `__reversed__`
* `__class_getitem__`
The assumption here is that the underlying mapping is a `dict`,
just is done for `MappingProxyType.copy`
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 30, 2021

Not directly related to your PR, but something I noticed: The value type of Mapping is covariant, while the value type of MappingProxyType is invariant. Maybe this is something we should also change?

@BvB93
Copy link
Contributor Author

BvB93 commented Jul 30, 2021

Not directly related to your PR, but something I noticed: The value type of Mapping is covariant, while the value type of MappingProxyType is invariant. Maybe this is something we should also change?

Might as well while we're at it; done as of 4a864e9.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 95a45eb into python:master Jul 30, 2021
@BvB93 BvB93 deleted the mappingproxy branch July 30, 2021 15:05
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