Serhiy Storchaka added the comment:
See the grammar.
https://docs.python.org/3/reference/expressions.html#conditional-expressions
conditional_expression ::= or_test ["if" or_test "else" expression]
expression ::= conditional_expression | lambda_expr
`*()` is not an
Robert Spralja added the comment:
I understand that it's invalid synatax, but not why.
On Sat, 26 Feb 2022 at 10:07, Serhiy Storchaka
wrote:
>
> Serhiy Storchaka added the comment:
>
> It is an invalid syntax. Write foo(*((stri,) if stri else ())).
>
> --
> nosy: +serhiy.storchaka
Serhiy Storchaka added the comment:
It is an invalid syntax. Write foo(*((stri,) if stri else ())).
--
nosy: +serhiy.storchaka
resolution: -> not a bug
stage: -> resolved
status: open -> closed
___
Python tracker
New submission from Robert Spralja :
`
>>> def foo(num=1):
... return num
...
>>> foo(*(bool,) is bool else *())
File "", line 1
foo(*(bool,) is bool else *())
^
SyntaxError: invalid syntax
>>> foo(*(bool,) if bool else *())
File "", line 1
foo(*(bool,)