Skip to content

State of the Mypy cache makes check results unpredictable #10221

Closed
@exarkun

Description

@exarkun

The result of mypy checking a piece of code depends on both that code and the internal mypy cache. The same piece of code can cause mypy to produce two different results depending on the state of the mypy cache.

(A clear and concise description of what the bug is.)

To Reproduce

Run mypy 3 times. The first run is against version "A" of the demonstration code. The second run is against version "B" of the demonstration code and introduces some mypy errors. The third run is against version "A" of the demonstration code - again. But this time it comes with the same errors version "B" received.

[nix-shell:~/Work/python/tahoe-lafs]$ rm -rf .mypy_cache/
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ cat example-web.py
from twisted.web.client import HTTPClientFactory
from twisted.web.client import HTTPPageGetter

class Y(HTTPPageGetter):
    pass

class X(HTTPClientFactory):
    protocol = Y
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ mypy example-web.py
Success: no issues found in 1 source file
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ cat example-web.py
from twisted.web.client import HTTPClientFactory
from twisted.web.client import HTTPPageGetter

#                       vvvvvv
class Y(HTTPPageGetter, object):
#                       ^^^^^^
    pass

class X(HTTPClientFactory):
    protocol = Y
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ mypy example-web.py
example-web.py:4: error: Cannot determine consistent method resolution order (MRO) for "Y"
example-web.py:8: error: Incompatible types in assignment (expression has type "Type[Y]", base class "HTTPClientFactory" defined the type as "Type[HTTPPageGetter]")
Found 2 errors in 1 file (checked 1 source file)
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ cat example-web.py
from twisted.web.client import HTTPClientFactory
from twisted.web.client import HTTPPageGetter

class Y(HTTPPageGetter):
    pass

class X(HTTPClientFactory):
    protocol = Y
(python38-tahoe-lafs)
[nix-shell:~/Work/python/tahoe-lafs]$ mypy example-web.py
example-web.py:4: error: Cannot determine consistent method resolution order (MRO) for "Y"
example-web.py:8: error: Incompatible types in assignment (expression has type "Type[Y]", base class "HTTPClientFactory" defined the type as "Type[HTTPPageGetter]")
Found 2 errors in 1 file (checked 1 source file)
(python38-tahoe-lafs)

Expected Behavior

The two runs of mypy against version "A" of the code should produce the same result.

Actual Behavior

The two runs of mypy against version "A" of the code produce different results.

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
ignore_missing_imports = True
plugins=mypy_zope:plugin
  • Python version used: 3.8.8
  • Operating system and version: NixOS 20.09.3009.8e78c2cfbae

Also required by the demo program above, Twisted 21.2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions