Upgrade mypy and fix resulting type errors/warnings

This commit is contained in:
Jeremy Singer-Vine
2024-08-06 14:14:34 -04:00
parent 6e769ea66d
commit 61e497640b
5 changed files with 17 additions and 15 deletions
+6 -3
View File
@@ -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
+1 -3
View File
@@ -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:
+6 -6
View File
@@ -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)
+2 -1
View File
@@ -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]:
+2 -2
View File
@@ -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