We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5209fcd commit 1f81b68Copy full SHA for 1f81b68
pypdf/_reader.py
@@ -314,10 +314,10 @@ def __init__(
314
__name__,
315
)
316
317
- self._we_opened = False
+ self._opened_automatically = False
318
if isinstance(stream, (str, Path)):
319
stream = FileIO(stream, "rb")
320
- self._we_opened = True
+ self._opened_automatically = True
321
weakref.finalize(self, stream.close)
322
323
self.read(stream)
@@ -363,8 +363,8 @@ def __exit__(
363
exc: Optional[BaseException],
364
traceback: Optional[TracebackType],
365
) -> None:
366
- """Write data to the fileobj."""
367
- if self._we_opened:
+ """Close the underlying stream if owned by the PdfReader"""
+ if self._opened_automatically:
368
self.close()
369
370
@property
0 commit comments