Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Support for interleaved errors

Abierto
#23 1 comentario 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
30/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
testing

Línea de trabajo

Start by reviewing the linked implementation in tests/mypy_helpers.py and its usage in tests/test_plugin.py, then inspect assertion rewriting in tests/init.py. Compare the proposed interleaved-error format with the current test expectations and determine the required plugin behavior and test coverage before deciding whether the approach can be supported.

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

Descripción

reporting

Here's what I came up with while trying to replicate mypy's own testcases, which interleave the expected errors in the source code like so:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/test_plugin.py

The implementation is here:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/mypy_helpers.py

In a failure case, the failed assertion output will look like:

>       assert actual == expected
E       assert 'from pynamod...ibute "lower"' == 'from pynamodb..._attr.lower()'
E           from pynamodb.attributes import UnicodeAttribute
E           from pynamodb.models import Model
E
E           class MyModel(Model):
E               my_attr = UnicodeAttribute(null=True)
E
E           reveal_type(MyModel.my_attr)  # E: Revealed type is 'pynamodb.attributes._NullableAttribute[pynamodb.attributes.UnicodeAttribute, builtins.str]'
E           reveal_type(MyModel().my_attr)  # E: Revealed type is 'Union[builtins.str*, None]'
E         - MyModel().my_attr.lower()  # E: Item "None" of "Optional[str]" has no attribute "lower"
E         + MyModel().my_attr.lower()

Of course, this requires assertion rewriting, which would've been done in the pytest plugin normally:
https://github.com/ikonst/pynamodb-mypy/blob/9453404f576c4ead04749d61eb041e10bec13229/tests/__init__.py#L3

There are two advantages of interleaving the errors in the test code:

  1. changing the test code does not necessitate updating of line numbers
  2. updating the test code is easier (by diffing the program against the "expected program", i.e. data-driven testing)

Have you considered allowing a similar approach?

Lenguaje dominante
Python
Estrellas
257
Forks
33
Métricas de merge de PR
Sin PR fusionados en 30 d

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.

Más de realpython/pytest-mypy

Todos los issues de realpython/pytest-mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.