Skip to content

SupportsAbs not compatible with NamedTuple #1485

@rwbarton

Description

@rwbarton
from typing import SupportsAbs, NamedTuple

class Point(NamedTuple('Point', [('x', int), ('y', int)]), SupportsAbs[int]):
    def __abs__(p) -> int:
        return abs(p.x) + abs(p.y)

def test(a: Point) -> bool:
    return abs(a) == 2  # E: Argument 1 to "abs" has incompatible type "Point"; expected SupportsAbs[None]

There's no error in test if the NamedTuple superclass of Point is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions