-
Notifications
You must be signed in to change notification settings - Fork 17
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
Automatically close objects via __del__
#142
Conversation
@@ -188,8 +188,6 @@ def test_open_new(): | |||
|
|||
|
|||
def test_open_invalid(): | |||
with pytest.raises(TypeError, match=re.escape("__init__() missing 1 required positional argument: 'input_data'")): | |||
pdf = pdfium.PdfDocument() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this test case because it doesn't check anything pypdfium2-specific. This is common Python behaviour.
Thereby, we avoid an "unraisable exception" warning when running tests (__del__
is still called, even if initialisation failed due to a parameter error handled by Python and the actual constructor code was never reached).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, theoretically, we could add some hasattr()
check to suppress these warnings, but I don't think that's worth it, given that this only happens in case of serious API misuse.
This avoids an additional variable. Nice side effect: Most PDFium methods have checks against passing in nullptr (None). If callers try to use an object after its `.raw` attribute has been set to None, now nothing should happen (as opposed to a segmentation fault). Also, it's good to remove the reference to the ctypes representation on close() to directly enqueue it for being discarded.
No description provided.