Mypy false positive for `converter` class attribute in `logging.Formatter` class.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
Descripción
Bug Report
Mypy false positive: Mypy thinks that setting the converter class attribute for a subclass of logging.Formatter to something like time.gmtime is wrong.
To Reproduce
class UTCFormatter(logging.Formatter):
"""An exact match for the `logging.Formatter` class, except that it logs the time in UTC."""
converter = time.gmtime
Expected Behavior
No error, since time.gmtime is annotated as def gmtime(seconds: float | None = None, /) -> struct_time: ... and the converter attribute is annotated as converter: Callable[[float | None], struct_time].
Actual Behavior
logger.py:45: error: Incompatible types in assignment (expression has type "Callable[[], struct_time]", base class "Formatter" defined the type as "Callable[[float | None], struct_time]") [assignment]
Your Environment
- Mypy version used: 1.16.0 (compiled: yes)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.13.4 (on Linux)
By the way, this issue didn't exist in my Python3.12 environment with an older version of mypy installed, but I don't have access to that environment right now so I can't provide which mypy version it had.
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
No se nombra ningún archivo del repositorio ni ninguna prueba. Reproduce el ejemplo de UTCFormatter con mypy 1.16.0 en Python 3.13.4, localiza después el manejo de las asignaciones de subclases a atributos de clase invocables y añade una prueba de regresión; se considera terminado cuando no haya ningún error de asignación para time.gmtime, mientras que las sobrescrituras incompatibles sigan siendo diagnosticadas.
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
- 48/100