
On Fri, Apr 16, 2021 at 6:24 PM Sebastian Rittau <srittau@rittau.biz> wrote:
Am 16.04.21 um 18:59 schrieb Jukka Lehtosalo:
However, what about type aliases:
A = () => int # Hmm?
An alternative for aliases is to rethink the rejected idea from PEP 613 and allow type aliases to be defined like this:
A: TypeAlias[() => int]
This has the problem that A has no value at runtime, so it can only be used in a type context, and we'd still need string literal escaping for cast("A", f), etc. It would also be a bit tricky to use for runtime introspection, and I don't want to regress things for users of pydantic, etc. -- though runtime introspection might work, since the target type is stored in __annotations__.
type A = list[int]
As introducing "type" as a keyword could be problematic (although I might be mistaken), we could reuse "def":
def A = list[int]
I *believe* that the new parser can handle "type" (i.e. context-sensitive keywords), but I'm not sure. "def" sounds like the best option from the existing real keywords. Jukka