python / python/mypy

stubtest and @deprecated

Abierto
#20,160 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug topic-pep-702 topic-stubtest
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug Report

The @warnings.deprecated decorator adds a few dunders to classes it decorates. This causes stubtest to complain about differences between stub and implementation, unless these changes are added manually to the stubs. I think we should special case @deprecated to ignore these differences.

To Reproduce

For example, adding the following test to StubtestUnit:

    @collect_cases
    def test_deprecated(self) -> Iterator[Case]:
        yield Case(
            stub="""
            from warnings import deprecated

            @deprecated("")
            class Foo: ...
            """,
            runtime="""
            from warnings import deprecated

            @deprecated("")
            class Foo:
                pass
            """,
            error=None,
        )

causes the following error when running the tests with Python 3.13:

E           AssertionError: error: test_module.Foo.__deprecated__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime:
E             ''
E             
E             error: test_module.Foo.__init_subclass__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime: in file /opt/pyenv/versions/3.13.8/lib/python3.13/warnings.py:621
E             def (*args, **kwargs)
E             
E             error: test_module.Foo.__new__ is not present in stub
E             Stub: in file test_module.pyi
E             MISSING
E             Runtime: in file /opt/pyenv/versions/3.13.8/lib/python3.13/warnings.py
E             def (*args, **kwargs)
E             
E             Found 3 errors (checked 1 module)
E             
E           assert {'test_module....Foo.__new__'} == set()
E             
E             Extra items in the left set:
E             'test_module.Foo.__deprecated__'
E             'test_module.Foo.__new__'
E             'test_module.Foo.__init_subclass__'
E             Use -v to get more diff

Interestingly, this is different from what we see in typeshed (python/typeshed#14893):

error: jwcrypto.jwt.JWTMissingKeyID.__init_subclass__ is inconsistent, stub does not have *args parameter "args"
Stub: in file /home/runner/work/typeshed/typeshed/stubs/jwcrypto/jwcrypto/jwt.pyi:139
def (cls: type[builtins.object])
Runtime: in file /opt/hostedtoolcache/Python/3.13.8/x64/lib/python3.13/warnings.py:621
def (*args, **kwargs)

Your Environment

  • Mypy version used: master for the test above, 1.18.2 in typeshed CI
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13

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 prueba propuesta en StubtestUnit y reprodúcela en Python 3.13. Traza la comparación que hace stubtest de las clases decoradas con warnings.deprecated y consigue que la prueba pase ignorando únicamente las diferencias añadidas por el decorador.

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

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 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.