Skip to content

Issue with Narrowing #21173

@George-Ogden

Description

@George-Ogden

This is a duplicate of #20600, although I cannot reopen it. Here is an example to reproduce. I believe it was introduced in v1.20.0.

from dataclasses import dataclass
from typing import TypeGuard, Self


@dataclass
class ErrorCase:
    x: int

    def __eq__(self, other: object) -> TypeGuard[Self]:
        return (
            type(other)
            is type(self)
        ) and (
                self.x # error: "object" has no attribute "x"
                == other.x
        )

The error on line 14 is a false-positive.

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