Skip to content

Using type(other) is type(self) only works when revealing types #20275

Description

@George-Ogden

Bug Report

fromtypingimportreveal_typeclassX:
y: intdef__eq__(self, other: object) ->bool:
returntype(other) isreveal_type(type(self)) andother.y==self.y

This works as you would expect - no errors.
But make a small change and

fromtypingimportreveal_typeclassX:
y: intdef__eq__(self, other: object) ->bool:
returntype(other) istype(self) andother.y==self.y

error: "object" has no attribute "y"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions