Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: mypy (https://github.com/python/mypy)
+ mypyc/analysis/dataflow.py:615: error: Result type of - incompatible in assignment [misc]
+ mypyc/analysis/dataflow.py:618: error: Result type of | incompatible in assignment [misc]
+ mypyc/analysis/dataflow.py:619: error: Result type of - incompatible in assignment [misc]
+ mypyc/analysis/dataflow.py:622: error: Result type of | incompatible in assignment [misc]
+ mypyc/analysis/dataflow.py:685: error: Incompatible types in assignment (expression has type "AbstractSet[T]", target has type "set[T]") [assignment]
+ mypyc/analysis/dataflow.py:691: error: Incompatible types in assignment (expression has type "AbstractSet[T]", target has type "set[T]") [assignment]
+ mypy/stubtest.py:1242: error: Unsupported operand types for | ("set[str]" and "set[str]") [operator]
+ mypy/stubtest.py:1242: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-operator for more info
core (https://github.com/home-assistant/core)
+ homeassistant/helpers/device_registry.py:275: error: Incompatible types in assignment (expression has type "set[str]", variable has type "frozenset[str]") [assignment]
+ homeassistant/components/logbook/helpers.py:109: error: Unsupported operand types for | ("set[EventType[Any] | str]" and "set[str]") [operator]
pegen (https://github.com/we-like-parsers/pegen)
+ src/pegen/grammar.py:180: error: Result type of | incompatible in assignment [misc]
+ src/pegen/grammar.py:215: error: Result type of | incompatible in assignment [misc]
+ src/pegen/parser_generator.py:255: error: Result type of - incompatible in assignment [misc]
+ src/pegen/parser_generator.py:283: error: Result type of | incompatible in assignment [misc]
CPython (peg_generator) (https://github.com/python/cpython)
+ Tools/peg_generator/pegen/grammar_analysis.py:123: error: Result type of - incompatible in assignment [misc]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/coverage.py: note: In function "_load_modules":
+ sphinx/ext/coverage.py:101:13: error: Result type of | incompatible in assignment [misc]
+ sphinx/ext/coverage.py: note: In function "_determine_py_coverage_modules":
+ sphinx/ext/coverage.py:137:13: error: Result type of | incompatible in assignment [misc]
|
Collaborator
Author
|
The primer fallout is lower than feared and needs analysis. homeassistant/helpers/device_registry.py:275 is actually a true positive: __optional_keys__: ClassVar[frozenset[str]]
...
cls.__optional_keys__ = (
frozenset(cls._field_names)
- cls.__required_keys__
- _DEPRECATED_DEVICE_INFO_PARAMETERS.keys()
)But: frozenset() - frozenset() - {}.keys() # -> set() |
Collaborator
Author
|
Primer analysis:
Summary: Two hits are due to a mypy bug, with a fix in progress. Apart from that all hits are true positives, of which a few may have real consequences. My overall assessment is that this PR is definitely worth it: Fairly low churn, which can catch potential real-life bugs. It will also prevent future accumulations of this problem. |
srittau
marked this pull request as ready for review
October 28, 2026 14:22
This branch has not been deployed
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exploratory PR for narrowing the in-place operators of
MutableSet.Rationale:
setandfrozenset– which probably make up 99% ofAbstractSetimplementation uses – have a narrower API that whatMutableSetcurrently accepts: The former only acceptsetandfrozensetoperands in their operators. For otherAbstractSets, Python falls back to the operand's reflected method.An underlying problem is the dichotomy of these classes as ABCc and pseudo-protocols: As ABCs they accept more types than the protocol would. This PR limits
MutableSet's API to whatsetandfrozensetactually support. This leads to soundness problems:Claude Code (Claude Opus 5.5) (which helped me prepare this PR) added extensive test coverage for this, which I believe is warranted in this fundamental case.