-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Accept iterables in methods of Set and MutableSet #14653
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/dtypes/cast.py:865: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/dtypes/cast.py:866: error: Unused "type: ignore" comment [unused-ignore]
pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/main.py:907: error: Set comprehension has incompatible type Set[int | str]; expected Set[str | None] [misc]
- pydantic/v1/main.py:907: note: Left operand is of type "set[str] | dict_keys[str, Any]"
ibis (https://github.com/ibis-project/ibis)
- ibis/backends/sql/datatypes.py:1398: error: Unsupported operand types for - ("set[type[Never]]" and "set[type[SqlglotType]]") [operator]
- ibis/expr/datatypes/tests/test_core.py:581: error: Unsupported operand types for - ("set[type[Never]]" and "set[AnnotableMeta]") [operator]
jax (https://github.com/google/jax)
+ jax/_src/interpreters/batching.py:231: error: Unused "type: ignore" comment [unused-ignore]
discord.py (https://github.com/Rapptz/discord.py)
- ...typeshed_to_test/stdlib/typing.pyi:1043: note: "update" of "TypedDict" defined here
+ ...typeshed_to_test/stdlib/typing.pyi:1044: note: "update" of "TypedDict" defined here
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
- discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/bot.py:290: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
- discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name" [misc]
+ discord/ext/commands/bot.py:314: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command" [misc]
|
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ... | ||
def __iand__(self, value: AbstractSet[object], /) -> Self: ... | ||
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... | ||
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ... # type: ignore[override,misc] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type ignores seem like a good indication that we shouldn't make this change: we shouldn't claim AbstractSet supports something if the concrete set class doesn't support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't get what you mean: both set
and collections.abc.Set
have this method, but collections.abc.Set
supports Iterable, while [C implementation of] set
not, maybe the problem is that AbstractSet
is used to represent collections.abc.Set
and [in typeshed] set
is a subclass of MutableSet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an ABC like collections.abc.Set
is used, a lot (most?) of the time the concrete runtime type that gets used will be builtins.set
, just as when Sequence
is used, the runtime type will usually be list
or tuple
, and with Mapping
it will be dict
. So if we claim that some operation is supported on collections.abc.Set
, but it doesn't actually work with builtins.set
, we'll fail to detect issues on code that uses builtins.set
and uses these methods.
Of course, the tradeoff is that we emit false positives on some operations on other collections.abc.Set
implementations, including those that rely on the mixins in the ABC. Maybe that's enough reason to make the change in this PR.
No description provided.