Skip to content

Recent change to tuple constructor breaks subclasses of tuples #8275

Closed
@erictraut

Description

@erictraut

A recent change to the tuple.__new__ method in builtins.pyi introduced an overload:

    @overload
    def __new__(cls) -> tuple[()]: ...

This overload is problematic for classes that derive from specialized tuples.

class MyTuple(tuple[int, str, str]):
    ...

x = MyTuple()
reveal_type(x) # tuple[()] !!!!

Because of this overload, the wrong type is evaluated.

I think this overload should return Self, not tuple[()]. Admittedly, that doesn't produce the ideal type evaluation for tuple(). It produces tuple[Any, ...] rather than tuple[()].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions