Skip to content

Conversation

Gatsik
Copy link
Contributor

@Gatsik Gatsik commented Aug 27, 2025

No description provided.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

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

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.

Copy link
Contributor Author

@Gatsik Gatsik Aug 28, 2025

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

Copy link
Member

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.

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