Cannot copy symbol nodes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction command in the issue and inspect the plugin code at src/prisma/mypy.py, especially the SymbolTableNode copying path demonstrated in demo_bug.py. Compare behavior across the noted mypy versions and establish whether plugin-visible nodes should support copying; done means the reproduction no longer raises the missing-name TypeError and the expected node type update remains isolated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100