Cannot copy symbol nodes
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
When using the plugin API calling copy.copy on a symbol node causes this error
File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 102, in copy
return _reconstruct(x, None, *rv)
File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 265, in _reconstruct
y = func(*args)
File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copyreg.py", line 101, in __newobj__
return cls.__new__(cls, *args)
TypeError: __init__() missing required argument 'name' (pos 1)
This code worked prior to v0.971.
Sample code:
new = node.copy() # node is of type `SymbolTableNode`
new.node = copy.copy(new.node) # the error happens here
assert isinstance(new.node, Var)
new.node.type = node.node.type.items[0]
For the full plugin code see https://github.com/RobertCraigie/prisma-client-py/blob/main/src/prisma/mypy.py.
To Reproduce
$ git clone https://github.com/RobertCraigie/prisma-client-py@mypy-repro-plugin-bug
# setup venv
$ pip install -U -e .[dev] mypy==0.991
$ prisma generate --schema=tests/data/schema.prisma
$ mypy --show-traceback demo_bug.py
Expected Behavior
Nodes should be copyable through either a custom .copy() method or using the builtin copy module
Additional Context
The reason I need to copy the node in the first place is because my plugin modifies the types of variables under certain conditions. I previously found that without copying, these changes would be incorrectly leaked to other places.
It also may be possible that my plugin is copying nodes unnecessarily, I may have been overly cautious and I haven't kept up to do date with internal mypy changes.
Your Environment
- Mypy version used:
0.971(this also happens on0.991) - Mypy command-line flags:
--show-traceback - Python version used:
3.10.8 - Mypy configuration options from
mypy.ini(and other config files):
[mypy]
pretty = True
show_error_codes = True
plugins = prisma.mypy, pydantic.mypy
exclude = tests/integrations
strict_equality = True
implicit_reexport = True
check_untyped_defs = True
no_implicit_optional = True
warn_return_any = True
warn_unreachable = True
warn_unused_configs = True
warn_unused_ignores = True
warn_redundant_casts = True
disallow_any_generics = True
disallow_untyped_defs = True
disallow_untyped_calls = True
disallow_subclassing_any = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
cache_fine_grained = True
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
Comienza con el comando de reproducción del issue e inspecciona el código del plugin en src/prisma/mypy.py, especialmente la ruta de copia de SymbolTableNode demostrada en demo_bug.py. Compara el comportamiento entre las versiones de mypy indicadas y determina si los nodos visibles para el plugin deberían admitir copias; se considera terminado cuando la reproducción ya no provoca el TypeError de nombre ausente y la actualización esperada del tipo de nodo permanece aislada.
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
- 35/100