You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to work around #4997 by adding a dummy field to a dataclass which would not appear in __init__ (so init=False) or in fields() (so InitVar), but ran into a mypy crash when subclassing it.
Whilst the workaround is a nasty hack, it works at runtime, so IMO mypy should cope with it.
test.py:
importdataclasses@dataclasses.dataclassclassStruct:
_dummy: dataclasses.InitVar=dataclasses.field(init=False)
@dataclasses.dataclassclassHeader(Struct):
foo: int
mypy output:
$ ~/src/mypy/venv/bin/mypy test.py --show-traceback
test.py:10: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.730+dev.c610a312853921d09083f7525c183810e4232056
Traceback (most recent call last):
File "/home/josh/src/mypy/venv/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/build.py", line 162, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/build.py", line 2559, in dispatch
process_graph(graph, manager)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/build.py", line 2868, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/build.py", line 2961, in process_stale_scc
semantic_analysis_for_scc(graph, scc, manager.errors)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal_main.py", line 77, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal_main.py", line 202, in process_top_levels
patches)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal_main.py", line 330, in semantic_analyze_target
active_type=active_type)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 376, in refresh_partialself.refresh_top_level(node)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 387, in refresh_top_levelself.accept(d)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 4591, in accept
node.accept(self)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/nodes.py", line 925, in acceptreturn visitor.visit_class_def(self)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 1011, in visit_class_defself.analyze_class(defn)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 1082, in analyze_classself.analyze_class_body_common(defn)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 1091, in analyze_class_body_commonself.apply_class_plugin_hooks(defn)
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/semanal.py", line 1136, in apply_class_plugin_hooks
hook(ClassDefContext(defn, decorator, self))
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/plugins/dataclasses.py", line 352, in dataclass_class_maker_callback
transformer.transform()
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/plugins/dataclasses.py", line 84, in transformif info[attr.name].type isNone:
File "/home/josh/src/mypy/venv/lib/python3.7/site-packages/mypy/nodes.py", line 2428, in __getitem__raiseKeyError(name)
KeyError: '_dummy'
test.py:10: : note: use --pdb to drop into pdb
The text was updated successfully, but these errors were encountered:
I was trying to work around #4997 by adding a dummy field to a dataclass which would not appear in
__init__
(soinit=False
) or infields()
(soInitVar
), but ran into a mypy crash when subclassing it.Whilst the workaround is a nasty hack, it works at runtime, so IMO mypy should cope with it.
test.py:
mypy output:
The text was updated successfully, but these errors were encountered: