Ior assignment operator is flagged while equivalent __ior__() method call is not
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza ejecutando mypy en los fragmentos proporcionados de actualización de OrderedSet y compara la instrucción |= con la llamada equivalente a __ior__(). Rastrea cómo se comprueban estas dos formas; se considera terminado cuando la forma |= se acepta de manera coherente con la llamada al método sin un ignore.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 42/100