Open maxfischer2781 opened 4 years ago
One other alternative would be to default to mixed steno/standard typing, e.g. await Union[A, B]
in order to avoid introducing round parentheses as a grouping construct. Would that be an option, or just a workaround?
I'd rate it as a workaround for the time being. After some thought, unambiguous type hints seem preferable - so until we decide on what prefix TYPE infix TYPE
means, only allowing prefix and infix separately makes sense.
Long-term, I find it preferable if stenotype does not come with edge cases -- it removes a lot of the appeal of having an easy typing syntax if you need to remember where it applies.
Is your feature request related to a problem? Please describe. The infix Union stenotype grammar has ambiguous precedence with regards to prefix shorthands:
await A or B
can mean bothAwaitable[Union[A, B]]
orUnion[Awaitable[A], B]
.The meaning of this expression is currently implicitly defined by grammar structure:
UNION
is parsed beforeSHORTHANDS
. It producesUnion[Awaitable[A], B]
.Describe the solution you'd like Decide on, clearly define and document precedence of expressions. Decide whether grouping is needed.
I'm in favour of prefix shorthands taking precedence: Shorthands signify protocols, which require entirely different code structure when optional. E.g. a
Union[Iterable[A], B]
is used either asc: B = ...
or asfor c: A in ...
. While having used such a type, I assume it is extremely rare.Iff we want to be able to express both cases, grouping is needed. Parentheses are the canonical grouping symbol in Python, and I do not see any alternative. This would complicate tuple grammar similar to Python:
()
is an empty Tuple (not a valid type, so don't care).(A,)
is a Tuple of one element, while(A)
is justA
.(A, B)
and(A, B,)
is a Tuple of two elements.There is no need to define precedence of infix
or
and prefix?
. Semantically, they both define aUnion
.Describe alternatives you've considered We could disallow ambiguous notation, and require grouping. For example,
await A or B
would be an error. It would have to be either(await A) or B
orawait (A or B)
.This is a tradeoff between terseness of the common case and unambiguity in any case. Since type annotations are about correctness, favouring unambiguity over minor terseness would be a valid goal as well.