Ior assignment operator is flagged while equivalent __ior__() method call is not
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
A |= operation statement causes "Result type of | incompatible in assignment" while the equivalent method call is accepted without complaint. I haven't figured out to annotate the statement to prevent that complaint, and expect that the complaint is an error.
To Reproduce
I am composing an OrderedSet based on one of Ramond Hettinger's recipes (the weakref one), adding needed functionality and type annotations. As in the recipe, my OrderedSet class is based on collections.MutableSet. Adding an update method, this definition results in Result type of | incompatible in assignment on the "|=" statement:
def update(self, *others):
# type: (*AbstractSet) -> None
for o in others:
self |= o # Mypy Error: Result type of | incompatible in assignment
However, code for the method that is identical except for using the corresponding method call instead of the |= operator does not cause any complaints:
def update(self, *others):
# type: (*AbstractSet) -> None
for o in others:
self.__ior__(o) # No error.
I would prefer to use the |= statement, but have been unable to annotate the unaccepted statement in a way that prevents the complaint (short of using ignore). (There are other methods that suffer from similar obstacles, including the original __init__() included in Raymond's recipe. The example I'm using involves fewer incidental details.)
Expected Behavior
I believe the |= statement should be accepted without complaint.
Actual Behavior
Result type of | incompatible in assignment error on the "|=" statement.
Your Environment
- Mypy version used: mypy 0.902
- Python version used: Python 3.7.5
- Operating system and version: Ubuntu Linux 18.04
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst mypy für die bereitgestellten OrderedSet-Aktualisierungssnippets aus und vergleiche die |=-Anweisung mit dem äquivalenten Aufruf von __ior__(). Verfolge, wie diese beiden Formen geprüft werden; abgeschlossen ist die Aufgabe, wenn die |=-Form ohne einen ignore konsistent mit dem Methodenaufruf akzeptiert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 42/100