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

Conversation

jdufresne
Copy link
Contributor

@jdufresne jdufresne commented Feb 8, 2020

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.

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Does travis tests pass with this change (enable it first in your forked repo and wait for the travis build to finish)?
  • Is the new or changed code fully tested?
  • [ ] Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? N/A

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

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.
@codecov-io
Copy link

codecov-io commented Feb 8, 2020

Codecov Report

Merging #1281 into master will increase coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1281      +/-   ##
==========================================
+ Coverage   92.45%   92.59%   +0.13%     
==========================================
  Files          19       19              
  Lines        6415     6400      -15     
==========================================
- Hits         5931     5926       -5     
+ Misses        484      474      -10
Impacted Files Coverage Δ
redis/connection.py 81.28% <100%> (+0.57%) ⬆️
redis/client.py 85.97% <100%> (+0.17%) ⬆️
redis/utils.py 68.75% <0%> (ø) ⬆️
tests/test_multiprocessing.py 78.78% <0%> (ø) ⬆️
tests/test_encoding.py 96% <0%> (ø) ⬆️
tests/test_connection_pool.py 97.84% <0%> (ø) ⬆️
tests/test_pubsub.py 99.15% <0%> (ø) ⬆️
tests/test_sentinel.py 99.14% <0%> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d8d523...677a2fa. Read the comment docs.

@andymccurdy
Copy link
Contributor

I too do not like hiding these errors. I'm going to merge this but I'm concerned about what corner cases might be exposed in real world code that the test suite doesn't adequately cover. If the next release causes significant issues for folks I may end up reversing this.

@jdufresne
Copy link
Contributor Author

jdufresne commented Feb 12, 2020

I understand, thanks. The only potential side effect should be output on stderr, no breakage or change in functionality. If you do decide to revert it, can you please CC me and I'll see if I can address it more directly?

@andymccurdy
Copy link
Contributor

Sure, sounds good. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants