Skip to content
Discussion options

You must be logged in to vote

We did actually specify this in PEP 673

We reject type aliases containing Self. Supporting Self outside class definitions can require a lot of special-handling in type checkers. Given that it also goes against the rest of the PEP to use Self outside a class definition, we believe the added convenience of aliases is not worth it:

TupleSelf = tuple[Self, Self]  # Rejected

class Alias:
    def return_tuple(self) -> TupleSelf:  # Rejected
        return (self, self)

Someone even brought it up another repo after it had been submitted (which I can't find anymore). We just decided it wasn't worth the effort. I wouldn't be particularly opposed as long as it had to be bound by a class but the w…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Gollum999
Comment options

Answer selected by Gollum999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants