10000 Inconsistency in metaclass/Type interaction · Issue #6416 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Inconsistency in metaclass/Type interaction #6416

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
msullivan opened this issue Feb 16, 2019 · 1 comment · Fixed by #6419
Closed

Inconsistency in metaclass/Type interaction #6416

msullivan opened this issue Feb 16, 2019 · 1 comment · Fixed by #6419
Labels
bug mypy got something wrong priority-1-normal

Comments

@msullivan
Copy link
Collaborator

Since #6370, we reject the following code:

from typing import Type
class Meta(type):
    pass
class Thing(metaclass=Meta):
    pass

def foo(x: Type[Thing]) -> Type[Thing]:
    assert isinstance(x, Meta)
    return x

with the error Incompatible return value type (got "Meta", expected "Type[Thing]").

Previously this worked because we thought that Meta and Type[Thing] had no overlap and so the rest of the function after the assert wasn't checked.

This caused one error in S.

The answer might be that we need to consider Type[Thing] to be a subtype of Meta?

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Feb 16, 2019
@ilevkivskyi
Copy link
Member

The answer might be that we need to consider Type[Thing] to be a subtype of Meta?

IIRC this is already true, we need to fix proper subtype (which is still a separate visitor, see also #3297)

Also even with proper subtype fixed, this may not help since isinstance() can widen type, see
#6386. Or maybe better proper subtype check will fix both issues.

ilevkivskyi added a commit that referenced this issue Feb 23, 2019
Fixes #4616
Fixes #6416
Fixes #6386

Currently `Type[C]` is considered a subtype of metaclass of `C`, and I think this is right. The idea is to fix `ProperSubtypeVisitor.visit_type_type()` to match `SubtypeVisitor.visit_type_type()` (plus couple small updates to make the former used by `isinstance()` and `issubclass()`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0