python / python/mypy

Cannot copy symbol nodes

Aperta
#14,149 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-plugins
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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 on 0.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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il comando di riproduzione riportato nell’issue e ispeziona il codice del plugin in src/prisma/mypy.py, in particolare il percorso di copia di SymbolTableNode mostrato in demo_bug.py. Confronta il comportamento tra le versioni di mypy indicate e stabilisci se i nodi visibili al plugin debbano supportare la copia; il lavoro è completo quando la riproduzione non genera più il TypeError per nome mancante e l’aggiornamento previsto del tipo di nodo rimane isolato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.