Cannot copy symbol nodes
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue に記載された再現コマンドから始め、src/prisma/mypy.py の plugin コードを調べます。特に、demo_bug.py で示されている SymbolTableNode のコピー経路を確認してください。記載されている mypy の各バージョン間で動作を比較し、plugin から見えるノードがコピーをサポートすべきかを明らかにします。再現時に missing-name TypeError が発生しなくなり、期待される node type の更新が分離されたままになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100