python / python/mypy

False positive Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"

Abierto
#7,192 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug priority-1-normal topic-type-variables
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Note: I wasn't sure what a proper title was for this issue, so I chose one that is specific to the issue at hand. I checked typeshed, it looks like the issue is about mypy, not typeshed. I wouldn't be surprised if an issue already existed for this false positive.

Minimal repro:

assert isinstance(email, EmailMessage)

# Fine
r1 = email.get("List-Id", "")
# Fine
r2 = email.get("List-Id", "") or email.get("List-Unsubscribe", "")
# Fine
r3 = bool(email.get("List-Id", "") or email.get("List-Unsubscribe", ""))
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r4 = bool(
    email.get("Auto-Submitted", "") in ("no", "")
    or email.get("List-Unsubscribe", "")
)
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r5 = email.get("Auto-Submitted", "") in ("no", "") or email.get(
    "List-Unsubscribe", ""
)

Both are false positives.

Typeshed:

_T = TypeVar('_T')

class Message:
    ...
    def get(self, name: str, failobj: _T = ...) -> Union[_HeaderType, _T]: ...
  • What is the actual behavior/output? Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"

  • What is the behavior/output you expect? No error.

  • What are the versions of mypy and Python you are using? mypy 0.711, Python 3.6.7
    Do you see the same issue after installing mypy from Git master? haven't tried it but since 0.711 is fairly recent...

  • What are the mypy flags you are using? (For example --strict-optional)

[mypy]
ignore_missing_imports = True
follow_imports = skip
check_untyped_defs = False
strict_equality = True
disallow_incomplete_defs = True

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza con la reproducción mínima en Python y la firma mostrada de Message.get en typeshed, usando mypy 0.711, Python 3.6.7 y los flags de mypy indicados. Compara los dos falsos positivos reportados con el comportamiento esperado sin errores y, a continuación, sigue la ruta de comprobación de tipos que gestiona la llamada a get y la expresión booleana.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.