Skip to content

Commit 0f7e912

Browse files
committed
Python: PEP 604 -- allow writing union types as X | Y
Supprot the syntax newly introduced in python3.10. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent e7326d7 commit 0f7e912

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--sort=no
2+
--kinds-Python=+z
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
v input.py /^v: float | str = 'a'$/;" v typeref:typename:float|str
2+
f input.py /^def f(list: List[int|str], param: int | None) -> float|str:$/;" f typeref:typename:float|str
3+
list input.py /^def f(list: List[int|str], param: int | None) -> float|str:$/;" z function:f typeref:typename:List[int|str] file:
4+
param input.py /^def f(list: List[int|str], param: int | None) -> float|str:$/;" z function:f typeref:typename:int|None file:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import List, Union
2+
v: float | str = 'a'
3+
4+
# Taken from https://www.python.org/dev/peps/pep-0604/
5+
def f(list: List[int|str], param: int | None) -> float|str:
6+
pass

parsers/python.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,17 @@ static bool skipVariableTypeAnnotation (tokenInfo *const token, vString *const r
12281228
if (readNext)
12291229
readToken (token);
12301230
/* skip subscripts and calls */
1231-
while (token->type == '[' || token->type == '(' || token->type == '.')
1231+
while (token->type == '[' || token->type == '(' || token->type == '.' || token->type == '|')
12321232
{
12331233
switch (token->type)
12341234
{
12351235
case '[': readNext = skipOverPair (token, '[', ']', repr, true); break;
12361236
case '(': readNext = skipOverPair (token, '(', ')', repr, true); break;
1237+
case '|':
1238+
reprCat (repr, token);
1239+
skipVariableTypeAnnotation (token, repr);
1240+
readNext = false;
1241+
break;
12371242
case '.':
12381243
reprCat (repr, token);
12391244
readToken (token);

0 commit comments

Comments
 (0)