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

Division by 0 does not raise ZeroDivisionError #2820

Closed
cooldannyboy opened this issue Feb 1, 2019 · 3 comments
Closed

Division by 0 does not raise ZeroDivisionError #2820

cooldannyboy opened this issue Feb 1, 2019 · 3 comments

Comments

@cooldannyboy
Copy link

I compile a python file test.py to a shared library by Cython, then use python to import this shared library for testing.The original python file raise ZeroDivisionError but this shared library doesn't.The following is the whole code to reproduce this issue

test.py:

try:
    print("try")
    l = [0.0]
    ll = [1.0/x for x in l]
    print("try end")

except ZeroDivisionError:
    print("exception")

Original python output:
try
exception

Shared library by Cython output:
try
try end

python version: 3.6
cython version: 0.29.3

@scoder scoder added this to the 0.29.4 milestone Feb 1, 2019
@scoder
Copy link
Contributor

scoder commented Feb 1, 2019

Thanks for the report. You can't catch it because it does not get raised. :)
It's an incomplete optimisation. I'll look into it.

@cooldannyboy
Copy link
Author

Thanks for the quick response!! Maybe I should revise the title...
Please also let me know if there is any existed setting or option could workaround it

@scoder scoder changed the title Can't catch ZeroDivisionError exception Division by 0 does not raise ZeroDivisionError Feb 1, 2019
@scoder scoder closed this as completed in 4278dbf Feb 1, 2019
@scoder
Copy link
Contributor

scoder commented Feb 1, 2019

Fixed in Cython 0.29.4.
AFAICT, there is no work-around for older versions.

scoder added a commit that referenced this issue Feb 1, 2019
…e. Also avoid using a (named) C macro where code generation will do.

See GH-2820.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants