With `--disallow-any-decorated`, `Any` detection logic changes w/wo decorator
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 clear and concise description of what the bug is.)
We expect that adding a decorator to a method will never produce a new mypy error unless the decorator itself introduces a new Any annotation, i.e. expect no new error if the decorator itself does not introduce any additional Any.
We also believe that it is difficult to call this behavior a bug. The behavior of the option itself seems self-evident in its own way.
But we would expect a situation where simply applying a harmless decorator would not change the presence or absence of errors.
To Reproduce
Here is a test case.
[case testDisallowAnyDecoratedShouldNeverAffect]
# flags: --disallow-any-decorated
import dataclasses
from typing import Any, Callable
from typing_extensions import TypedDict, TypeVar
class CtxAny(TypedDict):
place: Any
CallableT = TypeVar("CallableT")
def custom_decorator(func: CallableT) -> CallableT:
return func
class Something:
# No error
def do(self, ctx: CtxAny) -> None:
pass
@classmethod
# This emits an error, unexpected.
def do_classmethod(cls, ctx: CtxAny) -> None: # E: Type of decorated function contains type "Any" ("Callable[[Type[Something], CtxAny], None]")
pass
@custom_decorator
# This emits an error, unexpected.
def do_custom_decorator(self, ctx: CtxAny) -> None: # E: Type of decorated function contains type "Any" ("Callable[[Something, CtxAny], None]")
pass
[builtins fixtures/classmethod.pyi]
Expected Behavior
We expect do and others to be the same error-condition.
i.e. one of:
- No mypy errors emitted.
- All (containing
domethod) emits an error.- If some option allows us to emit an error on
domethod, it will be fine.
- If some option allows us to emit an error on
Actual Behavior
As shown in reproduction code.
Your Environment
- Mypy version used:current master
- Mypy command-line flags:
--disallow-any-decorated - Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.8.16, 3.11.3
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 el caso de prueba testDisallowAnyDecoratedShouldNeverAffect con --disallow-any-decorated y el fixture proporcionado builtins fixtures/classmethod.pyi. Compara los casos sin decorador, con classmethod y con decorador personalizado; después, haz que el comportamiento sea coherente y cubre la condición de error elegida con pruebas 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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100