Skip to content

Inconsistent results after 0.960 -> 0.971 migration #13422

Closed as not planned
Closed as not planned
@sobolevn

Description

@sobolevn

I am trying to migrate our huge code base from mypy 0.960 to 0.971, but odd things are happening.

For example, our CI fails with:

Run mypy --strict mypy_django_plugin
mypy_django_plugin/django/context.py:61: error: Unused "type: ignore" comment
mypy_django_plugin/django/context.py:62: error: Unused "type: ignore" comment
mypy_django_plugin/django/context.py:87: error: Untyped decorator makes function "model_modules" untyped
mypy_django_plugin/django/context.py:113: error: Returning Any from function declared to return "Optional[Type[Any]]"
mypy_django_plugin/django/context.py:233: error: Untyped decorator makes function "all_registered_model_classes" untyped
mypy_django_plugin/django/context.py:245: error: Untyped decorator makes function "all_registered_model_class_fullnames" untyped
mypy_django_plugin/django/context.py:251: error: Returning Any from function declared to return "str"
mypy_django_plugin/django/context.py:255: error: Returning Any from function declared to return "bool"
mypy_django_plugin/django/context.py:268: error: Returning Any from function declared to return "bool"
mypy_django_plugin/django/context.py:325: error: Unused "type: ignore" comment
mypy_django_plugin/django/context.py:335: error: Returning Any from function declared to return "Optional[Type[Any]]"

Link: https://github.com/typeddjango/django-stubs/runs/7838309248?check_suite_focus=true

Locally it works as expected (python and mypy versions do match):

(.venv) ~/Documents/github/django-stubs  fix-ci ✗                                 
» python --version
Python 3.9.9

(.venv) ~/Documents/github/django-stubs  fix-ci ✗                                    
» mypy --version                  
mypy 0.971 (compiled: yes)

(.venv) ~/Documents/github/django-stubs  fix-ci ✗                                    
» mypy --strict mypy_django_plugin
Success: no issues found in 20 source files

Since we have quite a complex structure, it might be something on our side.
So, what do we do?

We store all stubs for django in django-stubs folder.
At the same level we have mypy_django_plugin that does fancy stuff with ORM / etc.
Our plugin imports a lot of things from django itself (settings, .setup(), etc).

Here's the tricky part: 0.960 recognised these imports and their types.
Right now my local setup with 0.971 does the same thing.

But, 0.971 in our CI does not see our stubs. So, all types are just Anys. This is unexpected!

Link: https://github.com/typeddjango/django-stubs
Original PR: typeddjango/django-stubs#1108

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions