-
-
Notifications
You must be signed in to change notification settings - Fork 521
Closed
Labels
bugSomething isn't workingSomething isn't workingcrash"Internal error" crashes from mypy"Internal error" crashes from mypymypy-pluginIssues specific to mypy_django_pluginIssues specific to mypy_django_plugin
Description
Bug report
What's wrong
When running mypy with a model that extends from an abstract model that defines a manager, mypy crashes internally on the line where such model is defined.
The model (names are changed, but everything else is the same, the other abstract models only define fields):
class MyModel(SomeAbstractModel, OtherAbstractMode, SendableModel):
field = models.BooleanField(default=False, db_index=True)
def __str__(self) -> str:
return f'Model {self.field}'The abstract SendableModel model:
class SendableModel(UUIDModel):
processing_started = models.DateTimeField(blank=False, null=True)
sent = models.BooleanField(default=False, db_index=True)
objects = models.Manager()
to_send = ToSendManager()
class Meta:
abstract = TrueI get the following traceback:
./users/models.py:72: 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.770
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/usr/local/lib/python3.6/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 89, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 181, in build
sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr, extra_plugins
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 249, in _build
graph = dispatch(sources, manager, stdout)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2649, in dispatch
process_graph(graph, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 2956, in process_graph
process_stale_scc(graph, scc, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 3049, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal_main.py", line 78, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal_main.py", line 203, in process_top_levels
patches)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal_main.py", line 331, in semantic_analyze_target
active_type=active_type)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 350, in refresh_partial
self.refresh_top_level(node)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 361, in refresh_top_level
self.accept(d)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 4679, in accept
node.accept(self)
File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 939, in accept
return visitor.visit_class_def(self)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 1001, in visit_class_def
self.analyze_class(defn)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 1078, in analyze_class
self.analyze_class_body_common(defn)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 1087, in analyze_class_body_common
self.apply_class_plugin_hooks(defn)
File "/usr/local/lib/python3.6/site-packages/mypy/semanal.py", line 1147, in apply_class_plugin_hooks
hook(ClassDefContext(defn, base_expr, self))
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/main.py", line 37, in transform_model_class
process_model_class(ctx, django_context)
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/transformers/models.py", line 357, in process_model_class
initializer_cls(ctx, django_context).run()
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/transformers/models.py", line 71, in run
self.run_with_model_cls(model_cls)
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/transformers/models.py", line 231, in run_with_model_cls
base_manager_info=manager_info)
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/transformers/models.py", line 186, in create_new_model_parametrized_manager
method_node=sym.node)
File "/usr/local/lib/python3.6/site-packages/mypy_django_plugin/lib/helpers.py", line 346, in copy_method_to_another_class
assert bound_return_type is not None
AssertionError:
./users/models.py:72: : note: use --pdb to drop into pdb
If I remove the objects and to_send definitions from SendableModel then mypy works correctly.
Edit: Just found out that if I remove the manager definition from the abstract model but put it in the final model, it still crashes
How is that should be
Mypy should run normally without crashing.
System information
- OS: Alpine 3.4 (docker)
pythonversion: 3.6djangoversion: 2.2.6mypyversion: 0.770 (also happens with 0.782)django-stubsversion: 1.5.0
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcrash"Internal error" crashes from mypy"Internal error" crashes from mypymypy-pluginIssues specific to mypy_django_pluginIssues specific to mypy_django_plugin