Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong-exception-operation raised when concat tuple in except #9288

Closed
rany2 opened this issue Dec 9, 2023 · 1 comment · Fixed by #9289
Closed

wrong-exception-operation raised when concat tuple in except #9288

rany2 opened this issue Dec 9, 2023 · 1 comment · Fixed by #9289
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@rany2
Copy link

rany2 commented Dec 9, 2023

Bug description

Pylint wrong-exception-operation is raised when concatenating the tuple in except.

Consider this file a.py:

EXC = (ValueError,)

try:
	int("hi")
except (OSError,) + EXC as exc:
	print("caught it (exc={})".format(exc))

try:
	raise OSError("whatever")
except (OSError,) + EXC as exc:
	print("caught it (exc={})".format(exc))

Pylint complains with:

************* Module a
a.py:5:7: W0716: Invalid exception operation. Did you mean '((OSError, ), EXC)' instead? (wrong-exception-operation)
a.py:10:7: W0716: Invalid exception operation. Did you mean '((OSError, ), EXC)' instead? (wrong-exception-operation)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

when this case is valid.

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:5:7: W0716: Invalid exception operation. Did you mean '((OSError, ), EXC)' instead? (wrong-exception-operation)
a.py:10:7: W0716: Invalid exception operation. Did you mean '((OSError, ), EXC)' instead? (wrong-exception-operation)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

wrong-exception-operation shouldn't be raised

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)]

OS / Environment

No response

Additional dependencies

No response

@rany2 rany2 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Dec 9, 2023
@rany2
Copy link
Author

rany2 commented Dec 10, 2023

For anyone experiencing this issue, instead of disabling this warning you could do something like:

>>> x=(1,2,3,4)
>>> (*x, 5, 6, 7)
(1, 2, 3, 4, 5, 6, 7)

I think it looks better as well, so maybe pylint should have some style warning suggesting:

EXC = (ValueError,)

try:
	int("hi")
except (*EXC, OSError) as exc:
	print("caught it (exc={})".format(exc))

for

EXC = (ValueError,)

try:
	int("hi")
except (OSError,) + EXC as exc:
	print("caught it (exc={})".format(exc))

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Dec 10, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this Dec 10, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.0.3 milestone Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants