Skip to content

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

@George-Ogden

Description

@George-Ogden

Bug Report

from typing import reveal_type


class X:
    y: int

    def __eq__(self, other: object) -> bool:
        return type(other) is reveal_type(type(self)) and other.y == self.y

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

from typing import reveal_type


class X:
    y: int

    def __eq__(self, other: object) -> bool:
        return type(other) is type(self) and other.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