Ior assignment operator is flagged while equivalent __ior__() method call is not
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running mypy on the provided OrderedSet update snippets and compare the |= statement with the equivalent __ior__() call. Trace how these two forms are checked; done means the |= form is accepted consistently with the method call without an ignore.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100