diff --git a/pdfplumber/container.py b/pdfplumber/container.py index 9a9148c..2d664fe 100644 --- a/pdfplumber/container.py +++ b/pdfplumber/container.py @@ -13,14 +13,17 @@ class Container(object): cached_properties = ["_rect_edges", "_curve_edges", "_edges", "_objects"] @property - def pages(self) -> Optional[List[Any]]: ... # pragma: nocover + def pages(self) -> Optional[List[Any]]: # pragma: nocover + raise NotImplementedError @property - def objects(self) -> Dict[str, T_obj_list]: ... # pragma: nocover + def objects(self) -> Dict[str, T_obj_list]: # pragma: nocover + raise NotImplementedError def to_dict( self, object_types: Optional[List[str]] = None - ) -> Dict[str, Any]: ... # pragma: nocover + ) -> Dict[str, Any]: # pragma: nocover + raise NotImplementedError def flush_cache(self, properties: Optional[List[str]] = None) -> None: props = self.cached_properties if properties is None else properties diff --git a/pdfplumber/table.py b/pdfplumber/table.py index 7fae68e..e032f68 100644 --- a/pdfplumber/table.py +++ b/pdfplumber/table.py @@ -501,7 +501,7 @@ class TableSettings: intersection_y_tolerance: T_num = UNSET text_settings: Optional[Dict[str, Any]] = None - def __post_init__(self) -> "TableSettings": + def __post_init__(self) -> None: """Clean up user-provided table settings. Validates that the table settings provided consists of acceptable values and @@ -552,8 +552,6 @@ class TableSettings: if getattr(self, attr) is UNSET: setattr(self, attr, getattr(self, fallback)) - return self - @classmethod def resolve(cls, settings: Optional[T_table_settings]) -> "TableSettings": if settings is None: diff --git a/pdfplumber/utils/clustering.py b/pdfplumber/utils/clustering.py index 961ab31..b65b4d5 100644 --- a/pdfplumber/utils/clustering.py +++ b/pdfplumber/utils/clustering.py @@ -1,9 +1,9 @@ import itertools from collections.abc import Hashable from operator import itemgetter -from typing import Callable, Dict, Iterable, List, TypeVar, Union +from typing import Any, Callable, Dict, Iterable, List, Tuple, TypeVar, Union -from .._typing import T_num +from .._typing import T_num, T_obj def cluster_list(xs: List[T_num], tolerance: T_num = 0) -> List[List[T_num]]: @@ -36,15 +36,15 @@ def make_cluster_dict(values: Iterable[T_num], tolerance: T_num) -> Dict[T_num, return dict(itertools.chain(*nested_tuples)) -R = TypeVar("R") +Clusterable = TypeVar("Clusterable", T_obj, Tuple[Any, ...]) def cluster_objects( - xs: List[R], - key_fn: Union[Hashable, Callable[[R], T_num]], + xs: List[Clusterable], + key_fn: Union[Hashable, Callable[[Clusterable], T_num]], tolerance: T_num, preserve_order: bool = False, -) -> List[List[R]]: +) -> List[List[Clusterable]]: if not callable(key_fn): key_fn = itemgetter(key_fn) diff --git a/pdfplumber/utils/geometry.py b/pdfplumber/utils/geometry.py index 0f84e1d..93f5f3b 100644 --- a/pdfplumber/utils/geometry.py +++ b/pdfplumber/utils/geometry.py @@ -30,7 +30,8 @@ def obj_to_bbox(obj: T_obj) -> T_bbox: """ Return the bounding box for an object. """ - return bbox_getter(obj) + bbox: T_bbox = bbox_getter(obj) + return bbox def bbox_to_rect(bbox: T_bbox) -> Dict[str, T_num]: diff --git a/requirements-dev.txt b/requirements-dev.txt index ed81d31..3e2b23b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,9 +2,9 @@ black==24.8.0 flake8==7.1.1 isort==5.13.2 jupyterlab==3.6.7 -mypy==0.981 +mypy==1.11.1 nbexec==0.2.0 -pandas-stubs==2.2.2.240603 +pandas-stubs==2.2.2.240805 pandas==2.2.2 py==1.11.0 pytest-cov==5.0.0