Typing and Generics

typing.LiteralString

Marks strings known to originate from literals or statically safe combinations of them. Useful for interfaces that distinguish fixed text from arbitrary input. Not a sanitizer or runtime security check. Added in 3.11.

Formal Syntax & Structure

python syntaxpython
typing.LiteralString

Return Value

type expression

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import LiteralString
def heading(template:LiteralString)->str: return template.upper()print(heading('report'))
Python Reference