Indeed, there needs to be a way to get back and forth from the little typing language to Python and back.

That’s why I suggested the t-string format: in analogy to f-strings you could use {expression} constructs in there that would be evaluated in the normal Python environment (and syntax).

For the sake of argument lets assume for now that the little language uses
-  a : b to be equivalent to Mapping[a, b]
- [a] to be Sequence[a]
- (a, b) being Tuple[a, b] 
- (a, b) -> c being Callable,
- *a being Iterable[a]
- ?a being Optional[a]

Then your example would become something like

T = TypeVar(’T’)
Data = t’str : [(int, T)]’
Factory = t’(int, *str) -> ?[Data(T)]’

And note that I’m making up the syntax as I’m typing. Maybe it’s much better to use keywords (like optional, iterable) in stead of symbols).


Jack Jansen, <>,

If I can't dance I don't want to be part of your revolution -- Emma Goldman

On 8 Jan 2022, at 11:32, Serhiy Storchaka <> wrote:

08.01.22 01:59, пише:
If I can make a wild suggestion: why not create a little language for
type specifications?

We need a way to define aliases. For example, write:

Data = Mapping[str, Sequence[Tuple[int, T]]]
Factory = Callable[[int, Iterable[str]], Optional[list[Data[T]]]]

def get_foo_factory(type: str, id: int) -> Factory[Foo]: ...

instead of

def get_foo_factory(type: str, id: int) -> Callable[[int,
Iterable[str]], Optional[list[Mapping[str, Sequence[Tuple[int,
Foo]]]]]]: ...

Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: