Skip to content

Python allow multiple + or - after * and / operation without reporting exception "Invalid argument to operation" ? #130773

@ylwsas

Description

@ylwsas

Bug report

Bug description:

The plus and minus symbols can be regarded as numeric sign flag before an operands, but it seems Python can put multiple plus or minus after operators and before operands , and Python do not report any exception something like invalid argument to operation. The operations results depends on the number of signs for minus symbols, that is quite wired.

For Java or other language, they do report syntax errors. Think about the following codes, they all work.
Should we report syntax error for this situation?

# 
a=3; b=4
c=a *+ b
print(c)

a=3; b=4
c=a *++++++ b
print(c)


a=3; b=4
c=a *- b
print(c)

a=3; b=4
c=a *-- b
print(c)

a=3; b=4
c=a *--- b
print(c)

a=3; b=4
c=a /+++--- b
print(c)

'''Output: 
12
12
-12
12
-12
-0.75
'''

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions