Mypy crash on querysets
See original GitHub issueBug report
Mypy crashes
What’s wrong
class SomeEvent(models.Model):
user_id = models.IntegerField(null=False, unique=True)
exception_name = models.CharField(max_length=200, null=True, blank=True)
exception_type = models.CharField(max_length=200, null=True, blank=True)
And then in code:
data = (
models.SomeEvent.objects.values('exception_name').order_by().annotate(Count('exception_name'))
)
It crashes with:
some_handler.py:283: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.971
Traceback (most recent call last):
File "/Users/myuser/.virtualenvs/python38env/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/__main__.py", line 12, in console_entry
main(None, sys.stdout, sys.stderr)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/main.py", line 96, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/Users/myuser/.virtualenvs/python38env/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 "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 154, in build
result = _build(
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 230, in _build
graph = dispatch(sources, manager, stdout)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 2729, in dispatch
process_graph(graph, manager)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 3087, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 3185, in process_stale_scc
graph[id].type_check_first_pass()
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/build.py", line 2180, in type_check_first_pass
self.type_checker().check_first_pass()
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 329, in check_first_pass
self.accept(d)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 435, in accept
stmt.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1039, in accept
return visitor.visit_class_def(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 1823, in visit_class_def
self.accept(defn.defs)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 435, in accept
stmt.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1110, in accept
return visitor.visit_block(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 2200, in visit_block
self.accept(s)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 435, in accept
stmt.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 758, in accept
return visitor.visit_func_def(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 786, in visit_func_def
self._visit_func_def(defn)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 790, in _visit_func_def
self.check_func_item(defn, name=defn.name)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 852, in check_func_item
self.check_func_def(defn, typ, name)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 1037, in check_func_def
self.accept(item.body)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 435, in accept
stmt.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1110, in accept
return visitor.visit_block(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 2200, in visit_block
self.accept(s)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 435, in accept
stmt.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1176, in accept
return visitor.visit_assignment_stmt(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 2242, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checker.py", line 2436, in check_assignment
rvalue_type = self.expr_checker.accept(rvalue)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 3999, in accept
typ = node.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1771, in accept
return visitor.visit_call_expr(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 306, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 355, in visit_call_expr_inner
callee_type = get_proper_type(self.accept(e.callee, type_context, always_allow_any=True))
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 3999, in accept
typ = node.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1691, in accept
return visitor.visit_member_expr(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 2078, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 2089, in analyze_ordinary_member_access
original_type = self.accept(e.expr)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 3999, in accept
typ = node.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1771, in accept
return visitor.visit_call_expr(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 306, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 355, in visit_call_expr_inner
callee_type = get_proper_type(self.accept(e.callee, type_context, always_allow_any=True))
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 3999, in accept
typ = node.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1691, in accept
return visitor.visit_member_expr(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 2078, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 2089, in analyze_ordinary_member_access
original_type = self.accept(e.expr)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 3999, in accept
typ = node.accept(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/nodes.py", line 1771, in accept
return visitor.visit_call_expr(self)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 306, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 384, in visit_call_expr_inner
ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname,
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 893, in check_call_expr_with_callee_type
ret_type, callee_type = self.check_call(
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 958, in check_call
return self.check_callable_call(callee, args, arg_kinds, context, arg_names,
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 1086, in check_callable_call
new_ret_type = self.apply_function_plugin(
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy/checkexpr.py", line 773, in apply_function_plugin
return method_callback(
File "/Users/myuser/.virtualenvs/python38env/lib/python3.8/site-packages/mypy_django_plugin/transformers/querysets.py", line 272, in extract_proper_type_queryset_values
assert isinstance(default_return_type, Instance)
How is that should be
It should not crash
System information
- OS: MacOSX 12.5.1
python
version: 3.8.13django
version: 2.2.xmypy
version: 0.971django-stubs
version: 1.12.0django-stubs-ext
version: 0.5.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
mypy crashes with KeyError: 'django_stubs_ext' when using ...
Bug report mypy crashes when reaching code with Django queries that annotate fields, which did not happen which django-stubs version 1.8.0.
Read more >mypy-django/Lobby - Gitter
I'm trying to do a custom manager or a custom queryset as manager, and both get typed to Any, am I missing something?...
Read more >django-types · PyPI
... mypy can't crash due to Django config, and that non- mypy type checkers ... BaseManager from django.db.models.query import QuerySet # NOTE: there...
Read more >django-stubs-pr730 - Python Package Health Analysis | Snyk
FAQ · Is this an official Django project? · Is it safe to use this in production? · mypy crashes when I run...
Read more >django-stubs - Bountysource
mypy crashes when the return type of a manager method is a forward reference (similar to ... @property def ancestors(self) -> QuerySet: """Return...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
same thing happened for me.
mypy output:
the part of my code that mypy crashes on (
occasion_applier.py
lines 22 & 23):I don’t use any custom manager for
Occasion
model, nor forArea
. The related part is:My
mypy.ini
file:versions:
monkey patching is enabled too.
Same error as #701 . I tried upgrading to master and i can still replicate it.