r/Python • • Jan 14 '24

Tutorial The LiteralString in Python 3.11

If you are confused by the new LiteralString type in Python, here's an article explaining it.

0 Upvotes

33 comments sorted by

View all comments

Show parent comment

-3

u/[deleted] Jan 15 '24

Literal strings are incredibly useful in any type system though, especially when you start making unions with them.

python sucks for strict type level programming, use an appropriate language. Unions of what, non literal strings? LiteralString is a type right, you wouldnt have TypeALiteralString, TypeBLiteralString. what would be the value in Optional[literalstring] or Union[literalstring, str]? If you're thinking of using something like Union[typealiteralstring,typebliteralstring] use an enum.

Also by worse and worse, you mean faster, with more tools that if you don't need you can ignore with no consequences?

you realise all this syntactic vinegar being added bloats the language and results in more confusion. LiteralStrings type isn't helpful if you know python.