python / python/mypy

Cannot copy symbol nodes

Offen
#14,149 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-plugins
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Reproduktionsbefehl im Issue und untersuche den Plugin-Code unter src/prisma/mypy.py, insbesondere den in demo_bug.py demonstrierten Pfad zum Kopieren von SymbolTableNode. Vergleiche das Verhalten über die genannten mypy-Versionen hinweg und stelle fest, ob für Plugins sichtbare Nodes das Kopieren unterstützen sollten; abgeschlossen ist es, wenn die Reproduktion nicht mehr den fehlenden Namen TypeError auslöst und die erwartete Aktualisierung des Node-Typs isoliert bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.