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

Assertion failed in "except 1" #360

Closed
xiaxinmeng opened this issue Apr 17, 2023 · 2 comments
Closed

Assertion failed in "except 1" #360

xiaxinmeng opened this issue Apr 17, 2023 · 2 comments
Assignees

Comments

@xiaxinmeng
Copy link

The "except" statement is used to catch exceptions, and it expects to receive an exception class or tuple of exception classes from catching. In the code "except 1:", the number "1" is not an exception class, and it does not represent an exception. Therefore, it may be better to raise a TypeError instead of an assertion failure.

test.py

try:
  raise Exception()
except 1:
  pass

The output on Codon v0.16.0

Assert failed:	1 is not a class [test.py:14:1]
Expression:	t && t->getClass()
Source:		/github/workspace/codon/parser/visitors/translate/translate.cpp:544
Aborted (core dumped)

The output on CPython 3.10.8(As expected):

Traceback (most recent call last):
  File "/home/xxm/Desktop/Codon/test.py", line 15, in <module>
    raise Exception()
Exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/xxm/Desktop/Codon/test.py", line 16, in <module>
    except 1:
TypeError: catching classes that do not inherit from BaseException is not allowed

The output on RustPython 0.2.0 (As expected):

Traceback (most recent call last):
  File "/home/xxm/Desktop/Codon/test.py", line 15, in <module>
    raise Exception()
Exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/xxm/Desktop/Codon/test.py", line 16, in <module>
    except 1:
TypeError: isinstance() arg 2 must be a type or tuple of types, not int

Reproduce step:

download the Pre-built binaries for Linux
Type " codon run --release test.py" in the console.

Environment:
Ubuntu 18.04
Codon v0.16.0

@arshajii
Copy link
Contributor

Thanks for the report -- this shouldn't cause an assertion failure. This is something we'll catch at compile time with a compilation error.

@inumanag
Copy link
Contributor

Fixed in #604.

inumanag added a commit that referenced this issue Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants