FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Loosen some types to avoid pain in real-life situations by ilevkivskyi · Pull Request #4870 · python/typeshed · GitHub

Repository navigation

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

Merged
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:some-fixes
Dec 29, 2020
Merged

ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:some-fixes

Conversation

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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]

Copy link
Copy Markdown
Member Author

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

srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, apart from the build failure.

Copy link
Copy Markdown
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 merged commit fb753c4 into python:master Dec 29, 2020
ilevkivskyi deleted the some-fixes branch December 29, 2020 18:31

Copy link
Copy Markdown
Collaborator

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL