Skip to content

Inconsistency in metaclass/Type interaction #6416

@msullivan

Description

@msullivan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions