Skip to content

Subclassing Any Causes Unexpected Results #10027

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

Closed
dylanmann opened this issue Feb 5, 2021 · 1 comment
Closed

Subclassing Any Causes Unexpected Results #10027

dylanmann opened this issue Feb 5, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@dylanmann
Copy link

Bug Report
Subclassing Any (as a result of untyped library imports) results in mypy being unable to find a common ancestor for two classes. Is this expected behavior?

To Reproduce
Run mypy on this file:

from typing import Any, Type


def test(arg: Type[A]) -> None:
    return

def test2() -> None:
    for obj in (B, C):
        test(obj)  # ERROR IS HERE 


class A(Any):
    pass


class B(A):
    pass


class C(A):
    pass

Expected Behavior
Because B and C are both subclasses of A, I expected this to typecheck without error, and When I change A to be a subclass of object instead, mypy passes.

Actual Behavior

test.py:9: error: Argument 1 to "test" has incompatible type "Type[object]"; expected "Type[A]"

(Write what happened.)

Your Environment
Mac OS Catalina 10.15.7
brew installed python 3.9
mypy==0.800
No command line flags or mypy.ini

@dylanmann dylanmann added the bug mypy got something wrong label Feb 5, 2021
@hauntsaninja
Copy link
Collaborator

Thanks for the report! I fixed this a while back in #14404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants