Skip to content

Commit

Permalink
fix typing hints to include io.BytesIO
Browse files Browse the repository at this point in the history
  • Loading branch information
conitrade-as committed Jan 19, 2023
1 parent 639c169 commit d4107f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pdfplumber/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class COLORS:
T_contains_points = Union[Tuple[T_point, ...], List[T_point], T_obj]


def get_page_image(stream: BufferedReader, page_no: int, resolution: int) -> WandImage:
def get_page_image(
stream: Union[BufferedReader, BytesIO], page_no: int, resolution: int
) -> WandImage:
# If we are working with a file object saved to disk
if hasattr(stream, "name"):
filename = f"{stream.name}[{page_no}]"
Expand Down
8 changes: 4 additions & 4 deletions pdfplumber/pdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools
import logging
import pathlib
from io import BufferedReader
from io import BufferedReader, BytesIO
from types import TracebackType
from typing import Any, Dict, List, Optional, Tuple, Type, Union

Expand All @@ -25,7 +25,7 @@ class PDF(Container):

def __init__(
self,
stream: BufferedReader,
stream: Union[BufferedReader, BytesIO],
stream_is_external: bool = False,
pages: Optional[Union[List[int], Tuple[int]]] = None,
laparams: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -60,15 +60,15 @@ def __init__(
@classmethod
def open(
cls,
path_or_fp: Union[str, pathlib.Path, BufferedReader],
path_or_fp: Union[str, pathlib.Path, BufferedReader, BytesIO],
pages: Optional[Union[List[int], Tuple[int]]] = None,
laparams: Optional[Dict[str, Any]] = None,
password: str = "",
strict_metadata: bool = False,
) -> "PDF":

if isinstance(path_or_fp, (str, pathlib.Path)):
stream = open(path_or_fp, "rb")
stream: Union[BufferedReader, BytesIO] = open(path_or_fp, "rb")
stream_is_external = False
else:
stream = path_or_fp
Expand Down

0 comments on commit d4107f6

Please sign in to comment.