Skip to content

Commit af620d6

Browse files
committed
More docs
1 parent bbbc4e5 commit af620d6

4 files changed

Lines changed: 48 additions & 21 deletions

File tree

python_utils/containers.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ class CastedDictBase(types.Dict[KT, VT], abc.ABC):
113113
_value_cast: VT_cast[VT]
114114

115115
def __init__(
116-
self,
117-
key_cast: KT_cast[KT] = None,
118-
value_cast: VT_cast[VT] = None,
119-
*args: DictUpdateArgs[KT, VT],
120-
**kwargs: VT,
116+
self,
117+
key_cast: KT_cast[KT] = None,
118+
value_cast: VT_cast[VT] = None,
119+
*args: DictUpdateArgs[KT, VT],
120+
**kwargs: VT,
121121
) -> None:
122122
"""
123123
Initializes the CastedDictBase with optional key and value
@@ -138,7 +138,9 @@ def __init__(
138138
self.update(*args, **kwargs)
139139

140140
def update(
141-
self, *args: DictUpdateArgs[types.Any, types.Any], **kwargs: types.Any
141+
self,
142+
*args: DictUpdateArgs[types.Any, types.Any],
143+
**kwargs: types.Any
142144
) -> None:
143145
if args:
144146
kwargs.update(*args)
@@ -190,6 +192,7 @@ class CastedDict(CastedDictBase[KT, VT]):
190192
"""
191193

192194
def __setitem__(self, key: typing.Any, value: typing.Any) -> None:
195+
"""Sets `key` to `cast(value)` in the dictionary."""
193196
if self._value_cast is not None:
194197
value = self._value_cast(value)
195198

@@ -260,7 +263,7 @@ def __getitem__(self, key: types.Any) -> VT:
260263
return value
261264

262265
def items( # type: ignore
263-
self,
266+
self,
264267
) -> types.Generator[types.Tuple[KT, VT], None, None]:
265268
if self._value_cast is None:
266269
yield from super().items()
@@ -313,9 +316,9 @@ class UniqueList(types.List[HT]):
313316
_set: types.Set[HT]
314317

315318
def __init__(
316-
self,
317-
*args: HT,
318-
on_duplicate: OnDuplicate = 'ignore',
319+
self,
320+
*args: HT,
321+
on_duplicate: OnDuplicate = 'ignore',
319322
):
320323
self.on_duplicate = on_duplicate
321324
self._set = set()
@@ -348,18 +351,20 @@ def __contains__(self, item: HT) -> bool: # type: ignore
348351

349352
@typing.overload
350353
def __setitem__(
351-
self, indices: types.SupportsIndex, values: HT
352-
) -> None: ...
354+
self, indices: types.SupportsIndex, values: HT
355+
) -> None:
356+
...
353357

354358
@typing.overload
355359
def __setitem__(
356-
self, indices: slice, values: types.Iterable[HT]
357-
) -> None: ...
360+
self, indices: slice, values: types.Iterable[HT]
361+
) -> None:
362+
...
358363

359364
def __setitem__(
360-
self,
361-
indices: types.Union[slice, types.SupportsIndex],
362-
values: types.Union[types.Iterable[HT], HT],
365+
self,
366+
indices: types.Union[slice, types.SupportsIndex],
367+
values: types.Union[types.Iterable[HT], HT],
363368
) -> None:
364369
if isinstance(indices, slice):
365370
values = types.cast(types.Iterable[HT], values)
@@ -389,7 +394,7 @@ def __setitem__(
389394
)
390395

391396
def __delitem__(
392-
self, index: types.Union[types.SupportsIndex, slice]
397+
self, index: types.Union[types.SupportsIndex, slice]
393398
) -> None:
394399
if isinstance(index, slice):
395400
for value in self[index]:
@@ -404,13 +409,15 @@ def __delitem__(
404409
# runtime, mypy and pyright currently so we have to ignore the errors
405410
class SliceableDeque(types.Generic[T], collections.deque): # type: ignore
406411
@typing.overload
407-
def __getitem__(self, index: types.SupportsIndex) -> T: ...
412+
def __getitem__(self, index: types.SupportsIndex) -> T:
413+
...
408414

409415
@typing.overload
410-
def __getitem__(self, index: slice) -> 'SliceableDeque[T]': ...
416+
def __getitem__(self, index: slice) -> 'SliceableDeque[T]':
417+
...
411418

412419
def __getitem__(
413-
self, index: types.Union[types.SupportsIndex, slice]
420+
self, index: types.Union[types.SupportsIndex, slice]
414421
) -> types.Union[T, 'SliceableDeque[T]']:
415422
"""
416423
Return the item or slice at the given index.

python_utils/time.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def delta_to_seconds(interval: types.delta_type) -> float:
6969
def delta_to_seconds_or_none(
7070
interval: types.Optional[types.delta_type],
7171
) -> types.Optional[float]:
72+
"""Convert a timedelta to seconds or return None."""
7273
if interval is None:
7374
return None
7475
else:

python_utils/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
This module provides type definitions and utility functions for type hinting.
3+
4+
It includes:
5+
- Shorthand for commonly used types such as Optional and Union.
6+
- Type aliases for various data structures and common types.
7+
- Importing all types from the `typing` and `typing_extensions` modules.
8+
- Importing specific types from the `types` module.
9+
10+
The module also configures Pyright to ignore wildcard import warnings.
11+
"""
112
# pyright: reportWildcardImportFromLibrary=false
213
import datetime
314
import decimal

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
"""
2+
Setup script for the python-utils package.
13
4+
This script uses setuptools to package the python-utils library. It reads
5+
metadata from the `python_utils/__about__.py` file and the `README.rst` file to
6+
populate the package information. The script also defines the package
7+
requirements and optional dependencies for different use cases such as logging,
8+
documentation, and testing.
9+
"""
210
import pathlib
311

412
import setuptools

0 commit comments

Comments
 (0)