Skip to content

Inconsistency in metaclass/Type interaction #6416

Closed

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?

Activity

  1. ilevkivskyi commented on Feb 16, 2019

    @ilevkivskyi
    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.

  2. added a commit that references this issue on Feb 23, 2019
    ed0dcad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions