Skip to content

We lose information on assigning a type object to a variable #3067

Closed

Description

@sixolet
class A: pass

B: Type[A]
reveal_type(B)  # E: Revealed type is 'Type[__main__.A]'
B = A
reveal_type(B) # E: Revealed type is 'builtins.None'
b = B() # E: None not callable

Commentary from @pkch :

it seems the problem is that reveal_type calls meet_simple() on Type[A] and A, which are represented as TypeType and Callable. And meet_simple logic doesn't notice that they are compatible, so it returns None. I'm not sure what the difference is between meet_simple and meet_type, but the two would behave identically in this situation.

Attn @ilevkivskyi, who is hanging out in this area of code I think.

Activity

  1. gvanrossum commented on Mar 27, 2017

    @gvanrossum
    Member

    Looks like a bug in the binder?

  2. ilevkivskyi commented on Mar 27, 2017

    @ilevkivskyi
    Member

    I think this is closely related to PR #3025, namely to narrow_declared_type() it introduces.

  3. gvanrossum commented on Mar 27, 2017

    @gvanrossum
    Member

    But #3025 hasn't landed yet. Are you saying it would fix this?

  4. ilevkivskyi commented on Mar 27, 2017

    @ilevkivskyi
    Member

    Unfortunately, it does not fix it, but if I understand everything correctly, the fix will be very simple with this PR merged. (Or maybe Jukka could include the fix in his PR if he prefers.)

  5. ilevkivskyi commented on Oct 7, 2018

    @ilevkivskyi
    Member

    This now works correctly.

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