This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cleoold
Recipients Batuhan Taskaya, cleoold
Date 2021-03-24.02:14:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616552087.93.0.261462178392.issue43609@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-03-24 02:14:47cleooldsetrecipients: + cleoold, Batuhan Taskaya
2021-03-24 02:14:47cleooldsetmessageid: <1616552087.93.0.261462178392.issue43609@roundup.psfhosted.org>
2021-03-24 02:14:47cleooldlinkissue43609 messages
2021-03-24 02:14:47cleooldcreate