-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when deserialising ParamSpec in ClassDef #12257
Comments
Thanks, looks like a pretty straightforward bug in ParamSpec deserialisation. Line 1036 in 14de8c6
(Note that mypy doesn't yet have great support for classes that are generic over ParamSpec, but obviously it can do much better than this) |
Spotted in #11847 but that will probably not be merged in in time for v0.940 (and so a seperate PR for the fix might be preferred). |
I tried just selecting ParamSpec or TypeVar depending on class name but that doesn't seem to work. I am unsure how to fix this @classmethod
def deserialize(self, data: JsonDict) -> 'ClassDef':
assert data['.class'] == 'ClassDef'
type_to_class = {
'TypeVarType': mypy.types.TypeVarType,
'ParamSpecType': mypy.types.ParamSpecType,
}
res = ClassDef(data['name'],
Block([]),
[type_to_class[v['.class']].deserialize(v) for v in data['type_vars']],
)
res.fullname = data['fullname']
return res Edit: actually, this resolves issue in provided example, but second run of mypy causes a different error in original codebase. Unsure if this is the result of wrong fix or something unrelated. version: 0.940+dev.feca706d5f2540003ae8b24009d56dac7c067eba
Traceback (most recent call last):
File "/home/eugene/src/stella_bot/.venv/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/__main__.py", line 12, in console_entry
main(None, sys.stdout, sys.stderr)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/main.py", line 96, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/main.py", line 173, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 180, in build
result = _build(
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 256, in _build
graph = dispatch(sources, manager, stdout)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 2727, in dispatch
process_graph(graph, manager)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 3071, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 3178, in process_stale_scc
if not graph[id].type_check_second_pass():
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/build.py", line 2205, in type_check_second_pass
return self.type_checker().check_second_pass()
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 368, in check_second_pass
self.check_partial(node)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 379, in check_partial
self.accept(node)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 424, in accept
stmt.accept(self)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/nodes.py", line 738, in accept
return visitor.visit_func_def(self)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 774, in visit_func_def
self._visit_func_def(defn)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 785, in _visit_func_def
self.check_method_override(defn)
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 1486, in check_method_override
if self.check_method_or_accessor_override_for_base(defn, base):
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 1514, in check_method_or_accessor_override_for_base
if self.check_method_override_for_base_with_name(defn, name, base):
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 1600, in check_method_override_for_base_with_name
self.check_override(typ,
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/checker.py", line 1762, in check_override
self.msg.signature_incompatible_with_supertype(
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/messages.py", line 848, in signature_incompatible_with_supertype
self.pretty_callable_or_overload(original, context, offset=ALIGN_OFFSET + 2 * OFFSET,
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/messages.py", line 870, in pretty_callable_or_overload
self.note(pretty_callable(tp), context,
File "/home/eugene/src/stella_bot/.venv/lib/python3.8/site-packages/mypy/messages.py", line 1954, in pretty_callable
definition_args = [arg.variable.name for arg in tp.definition.arguments]
AttributeError: arguments |
@Fogapod Take a look at the solution in #11847. That should would. res = ClassDef(data['name'],
Block([]),
# https://github.com/python/mypy/issues/12257
[cast(mypy.types.TypeVarLikeType, mypy.types.deserialize_type(v))
for v in data['type_vars']],
) |
That branch produces same error for me. So must be a separate issue |
In that case it's likely because ParamSpec variables in Generic classes aren't supported yet to begin with. #11847 will add support and already includes the fix. Let's just go with that then. |
This PR adds a new Parameters proper type to represent ParamSpec parameters (more about this in the PR), along with supporting the Concatenate operator. Closes #11833 Closes #12276 Closes #12257 Refs #8645 External ref python/typeshed#4827 Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Bug Report
Mypy crashes with
AssertionError
after running it for the second time withnamespace-packages
option enabled. Looks like some typevar is improperly serialized in cache.First time mypy runs without issues:
Second time it crashes:
Traceback from dev version:
I added
print(data)
above the assert check, here's a few last lines before crash, last line causes it:So mypy doesn't like P typevar, it is defined here: https://github.com/Rapptz/discord.py/blob/45d498c1b76deaf3b394d17ccf56112fa691d160/discord/ext/commands/core.py#L111
Note that this ispatching library to usetyping_extensions.ParamSpec
, nottyping.ParamSpec
.typing.ParamSpec
produced same crash.I am unsure what exactly causes error, so I can't produce a smaller example of this crash. I will try to narrow it down in further comments.
To Reproduce
pip install discord.py @ git+https://github.com/Rapptz/discord.py@45d498c1b76deaf3b394d17ccf56112fa691d160
mypy main.py --namespace-packages
mypy main.py --namespace-packages
(run it again)main.py
Expected Behavior
mypy to not crash.
Actual Behavior
mypy crashes with AssertionError.
Your Environment
0.931
and latest master0.940+dev.feca706d5f2540003ae8b24009d56dac7c067eba
--namespace-packages
mypy.ini
(and other config files):3.8.12
/3.10.2
pip freeze
(new venv, after installing problematic package):The text was updated successfully, but these errors were encountered: