You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PDF class instance constructed with a file-like object closes that object upon deletion. open() does the same.
This behaviour is not documented, and is unexpected.
Code to reproduce the problem
importpdfplumberwithopen('sample.pdf', 'rb') assrc:
withpdfplumber.PDF(src) aspdf:
passassertnotsrc.closed, 'why is the file closed?'
PDF file
Any valid pdf file will do.
Actual behavior
File object given to PDF constructor is closed when close() method is called. See:
This disrupts using PDF class on temporary files and BytesIO objects, as those are destroyed upon being closed.
Expected behavior
File object given to PDF() constructor should remain in open state upon closing the resulting PDF class instance.
PDF class instance should only close those file objects it opened by itself.
Environment
pdfplumber version: 0.5.24
Python version: 3.8.2
OS: Windows 10
The text was updated successfully, but these errors were encountered:
Describe the bug
PDF class instance constructed with a file-like object closes that object upon deletion.
open()
does the same.This behaviour is not documented, and is unexpected.
Code to reproduce the problem
PDF file
Any valid pdf file will do.
Actual behavior
File object given to PDF constructor is closed when
close()
method is called. See:pdfplumber/pdfplumber/pdf.py
Line 72 in 954dc94
This disrupts using PDF class on temporary files and
BytesIO
objects, as those are destroyed upon being closed.Expected behavior
File object given to
PDF()
constructor should remain in open state upon closing the resulting PDF class instance.PDF class instance should only close those file objects it opened by itself.
Environment
The text was updated successfully, but these errors were encountered: