Skip to content

Binder doesn't work well with Type[...] #4616

Closed

Description

@ilevkivskyi

This code:

from typing import Union, Type

class C: ...

x: Union[C, Type[C]]

if isinstance(x, type) and issubclass(x, C):
    reveal_type(x)

Shows that the type of x is builtins.type. Ideally it should be Type[C].

Activity

  1. andrewbaxter commented on Apr 23, 2018

    @andrewbaxter

    Is this the same as:

    class A:
        x = 4
    
    
    i: type = A
    assert issubclass(i, A)
    print(i.x)
    

    which fails with:

    7: error: "type" has no attribute "x"
    

    ?

    mypy 0.590

    It looks like issubclass doesn't imply anything AFAICT, unlike isinstance.

    There's this workaround:

    i: type = A
    j: Type[A] = i
    print(j.x)
    

    but since this isn't in assertion format it seems more like a static check omission.

  2. ilevkivskyi commented on Apr 23, 2018

    @ilevkivskyi
    MemberAuthor

    Yes, this is the same bug.

  3. chadrik commented on Jul 24, 2018

    @chadrik
    Contributor

    Just got bit by this one.

  4. ilevkivskyi commented on Dec 22, 2018

    @ilevkivskyi
    MemberAuthor

    (Removing unions tag since there are repros without unions, and increasing priority to high since this appeared several times again.)

  5. 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