Skip to content

Cannot copy symbol nodes #14149

Open
Open
@RobertCraigie

Description

@RobertCraigie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pluginsThe plugin API and ideas for new plugins

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions