Skip to content

Loosen some types to avoid pain in real-life situations #4870

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 2 commits into from
Dec 29, 2020

Conversation

ilevkivskyi
Copy link
Member

In this diff:

  • Loosen set.__[i]sub__() to allow typical use cases (that work at runtime). Namely, allow removing unicode from a set of str, and allow removing optional values from non-optional sets.
  • Avoid using union return types in cryptography deserialization functions.
  • Tune SupportsItems so that dict implements it on Python 2.

About the first item, I think mypy should support the overloads on generic self-types (see https://mypy.readthedocs.io/en/stable/more_types.html#restricted-methods-in-generic-classes), but I am not sure about other type-checkers.

cc @JukkaL

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core.git)
- homeassistant/helpers/device_registry.py:597: error: Unsupported operand types for - ("Set[str]" and "Set[Optional[str]]")  [operator]

@ilevkivskyi
Copy link
Member Author

Hm, mypy thinks the overloads are unsafe, I will now try to tweak or ignore to make the build clean.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from the build failure.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core.git)
- homeassistant/helpers/device_registry.py:597: error: Unsupported operand types for - ("Set[str]" and "Set[Optional[str]]")  [operator]

@ilevkivskyi ilevkivskyi merged commit fb753c4 into python:master Dec 29, 2020
@ilevkivskyi ilevkivskyi deleted the some-fixes branch December 29, 2020 18:31
@hauntsaninja
Copy link
Collaborator

For posterity / to keep things linked, set difference was strict-ified in #3886

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.

3 participants