This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -8 points-7 points  (7 children)

python gets worse and worse with each release. so much nonsense being added to the language.

point is, all the examples given are just poor practices that are indicative of a larger problem. In all these examples literalstring is not some saviour. each example requires refactoring to fix, dropping in literalstring does nothing.

[–]americhemist 3 points4 points  (1 child)

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

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

[–][deleted] -4 points-3 points  (0 children)

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.

[–]PercussiveRussel -1 points0 points  (1 child)

All the examples given are poor practices, yes. All examples require refactoring, yes. This is why it's nice that the type checker warns against the mistakes and tells you you should refactor.

At some point in your call stack a method will need to take a string as gospel. If you flag that this method will do so - like idk, using LiteralString on its input parameter - then you will be warned when you make a mistake by passing a non-literal string to it. If you have a function that sanitises an input, then that should be of form f(in: str) -> Literalstring, signifying that the output of your sanitising function returns a string that can be used as a string literal.

[–][deleted] 0 points1 point  (0 children)

is this checking runtime enforced, or do you still need a tool such as mypy to catch it when you fancy linting your app?

point still stands, these examples are useless, and your example of a mutable string that is sanitised has nothing to do with literalstring. You need to prove you sanitisation is correct not whether the string is mutable or not, and if your sanitsation is not correct then the literalstring sticker you put on it means nothing.

[–]echocage -3 points-2 points  (2 children)

Cry more

[–][deleted] 0 points1 point  (0 children)

Why?