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

Stop hiding errors that occur inside __del__ methods #1281

Closed
wants to merge 1 commit into from
Closed

Stop hiding errors that occur inside __del__ methods #1281

wants to merge 1 commit into from

Commits on Feb 8, 2020

  1. Stop hiding errors that occur inside __del__ methods

    If an exception occurs inside the __del__ method, it should be reported
    to the developer. Not doing so could hide bugs.
    
    Python automatically handles exceptions inside __del__ methods, for
    example:
    
        class A:
            def __del__(self):
                1 / 0
    
        A()
        print("after del")
    
    Results in the output:
    
        $ python3 ~/blah.py
        Exception ignored in: <function A.__del__ at 0x7fbbf2bbfc20>
        Traceback (most recent call last):
          File "/home/jon/test.py", line 3, in __del__
            1 / 0
        ZeroDivisionError: division by zero
        after del
    
    From this example, we can see the bug was not hidden and the code after
    __del__ still executed.
    jdufresne committed Feb 8, 2020
    Configuration menu
    Copy the full SHA
    677a2fa View commit details
    Browse the repository at this point in the history