Message389429
Hi all, this is probably my first issue here, so don't blame me if I do something wrong lol
The ast.FunctionType gives syntax like (a, b) -> c for function types, this is ok, and also since Python 3.10 we can use X | Y to denote unions, this is ok. So Given the following two trees:
fun1 = ast.FunctionType(
argtypes=[],
returns=ast.BinOp(
left=ast.Name(id='int'),
op=ast.BitOr(),
right=ast.Name(id='float'),
)
)
fun2 = ast.BinOp(
left=ast.FunctionType(
argtypes=[],
returns=ast.Name(id='int'),
),
op=ast.BitOr(),
right=ast.Name(id='float'),
)
Calling:
print(ast.unparse(fun1))
print(ast.unparse(fun2))
The results are these:
() -> int | float
() -> int | float
So there is some ambiguity. By feeding this string to ast.parse(mode='func_type'), I know that it means "returning a union".
Don't know if there is any impact to simply add a pair of parens, or does this problem even matters at all.
I tested it using Python 3.10 a6 and Python 3.9.2. |
|
Date |
User |
Action |
Args |
2021-03-24 02:14:47 | cleoold | set | recipients:
+ cleoold, Batuhan Taskaya |
2021-03-24 02:14:47 | cleoold | set | messageid: <1616552087.93.0.261462178392.issue43609@roundup.psfhosted.org> |
2021-03-24 02:14:47 | cleoold | link | issue43609 messages |
2021-03-24 02:14:47 | cleoold | create | |
|