This is somewhat inspired by the "Tagged strings in python" thread, but from a 
different approach.
Specifically, rather than messing with runtime python, using static type 
analysis to help the usability of specific kinds of string literals.

It would be useful to take advantage of the `LiteralString` or `Literal` type 
hints to add structural validation to literals.

For *example*, if these could be subclassed to add a validation method:
    class MyLiteral(LiteralString):
        def __validate__(self):
            ...

or extended to allow something like regex in there generic type parameter:
    Literal[r"\w+"]
    LiteralString[r"\w+"]

then specific kinds of literal string can be "enforced" by static type 
checkers. 
Then IDEs could at the very least highlight that a string literal is not valid.

I stress these are just examples, the goal is to have a way to tell a static 
type checker what the structure of a string literal has to be.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/37OZHV2KNILDMO4WVOHOZZADVYPLQWE3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to