Conversation
- Runs on all pushes and pull requests - Checks only modified Python files for efficiency - Validates formatting and syntax with ruff Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Hey Hugo! Thanks for submitting this. I'm certain up for adding ruff auto-check. But the Maybe split the PR? I'd love to accept your contribution. |
|
Perplexity says this has been around since version 2.x:
----- PEP 758 try: try:
|
|
Hey Hugh, Perplexity might be right, but not in the way you're thinking. In Python 2 there as this style: try:
bad_function()
except DivisionByZero, e:
print('Oops, divide by zero!, Details:', e)So when it sees: try:
bad_function()
except DivisionByZero, FileNotFoundError:
print('Oh! Div or File!')It defines a variable or sets the value of FileNotFoundError to the exception itself. Meanwhile, running this uv run --python 3.8 main_no_parens.py
File "main_no_parens.py", line 11
except DivisionByZero, FileNotFoundError:
^
SyntaxError: invalid syntaxIn fact you get the same error in 3.9, 3.10, 3.11 and 3.12. But a slightly more friendly error which is a feature of 3.13: uv run --python 3.13 main_no_parens.py
File "/Users/michaelkennedy/Desktop/testing-exceptions/main_no_parens.py", line 11
except DivisionByZero, FileNotFoundError:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesizedStill it will NOT run in anything less than 3.14: uv run --python 3.14 main_no_parens.py
Testing no parens, running on 3.14.3 (main, Feb 4 2026, 01:51:49) [Clang 21.1.4 ]
Here comes a baddy! Divide by zero
Oh! Div or File!Success! This is why I do not want to accept the PR that removes the parentheses. It works, but not as you would expect in Python 2, and it fails in Python 3.13 and below. Here is the full code I tested against: import random
import sys
from decimal import DivisionByZero
baddies = [
('Divide by zero', DivisionByZero()),
('Value error', ValueError()),
('General exception', Exception()),
('File not found', FileNotFoundError()),
]
def main():
print(f'Testing parens, running on {sys.version}')
try:
bad_function()
except DivisionByZero, FileNotFoundError:
print('Oh! Div or File!')
except ValueError:
print('Value is bad!')
except Exception:
print('Other bad things')
def bad_function():
baddy = random.choice(baddies)
print(f'Here comes a baddy! {baddy[0]}')
raise baddy[1]
if __name__ == '__main__':
main() |
I am not removing the parentheses. I am adding them. |
Script can't run with Exception syntax.
Steps to replicate
uv run(as seen in the README.md)Error message
Fails with message that unparenthesized exceptions must be parenthesized:
The complete run