python / python/mypy

Truthiness of None Does not Narrow Optional Types

Abierto
#7,249 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

false-positive feature needs discussion priority-2-low topic-type-narrowing
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    I believe this is a bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

from typing import Optional

def the_method(maybe_int: Optional[int]):
    can_divide = bool(maybe_int)
    if can_divide:
        100 / maybe_int
  • What is the actual behavior/output?
error: Unsupported operand types for / ("int" and "None")
  • What is the behavior/output you expect?
    I would think that the conditional branch would recognize that only int values would ever make it there

  • What are the versions of mypy and Python you are using?
    mypy 0.720 with Python 3.7.3

  • Do you see the same issue after installing mypy from Git master?
    Yes still exists on master

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

Comienza con la reproducción mínima en Python del issue y sigue el punto de entrada del estrechamiento de tipos basado en la veracidad de mypy. El informe no menciona ningún archivo fuente ni prueba; se considera terminado cuando la rama condicional estrecha Optional[int] lo suficiente para que 100 / maybe_int pase la comprobación de tipos, con cobertura de regresión.

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
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.