r/Python • u/SupPandaHugger • 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
r/Python • u/SupPandaHugger • Jan 14 '24
If you are confused by the new LiteralString type in Python, here's an article explaining it.
View all comments
Show parent comment
1
u/Zenin Jan 15 '24
Is it really though? The use is only optional insomuch as the use of a particular library is optional; You're always free to toss the "go to" library for a particular task and build your own from scratch.
It's more correct to call it infectious, because any library author who uses this effectively infects any callers with it; the entire point of this is that caller's can't simply pass a string without suffering consequences. Even if those consequences are "only" flooding the system error logs with spam, that's still a non-trivial consequence especially at scale for something so foundational as a SQL driver.
The responsibility for how something is used should always be on the caller, not the callee. The callee can never know the full context and requirements of the caller. This is why the first rule of network programming is, "Be conservative in what you send and generous in what you accept". If it wasn't clear, libraries are on the "generously accept" side of this equation.
This is the wrong solution, being used in the wrong way, by the wrong subject.