|
24 | 24 |
|
25 | 25 | KeyT = typing.Union[str, int, slice, typing.Tuple[int, int], typing.List[int]]
|
26 | 26 | IndexT = typing.Union[int, slice, typing.Iterable[int], typing.Dict[str, typing.Tuple[int, int]]]
|
27 |
| -ResolvedMappingT = typing.Dict[str, typing.Union[slice, int, typing.Dict[str, typing.Any]]] |
28 |
| -AllowedMappingT = typing.Optional[typing.Dict[str, typing.Union[IndexT, typing.Dict[str, typing.Any]]]] |
| 27 | +ResolvedMappingT = typing.Dict[ |
| 28 | + str, |
| 29 | + typing.Union[int, slice, typing.Dict[str, typing.Any]], |
| 30 | +] |
| 31 | +DeclaredMappingT = typing.Dict[ |
| 32 | + str, |
| 33 | + typing.Union[int, slice, typing.Tuple[int, int], typing.List[int], typing.Dict[str, typing.Any]], |
| 34 | +] |
| 35 | + |
| 36 | +AllowedMappingT = typing.Optional[DeclaredMappingT] |
| 37 | + |
| 38 | +# Resolve mapping |
| 39 | +# _size_ : int -> _size_ + _mask_ |
| 40 | +# _mask_ : int -> _mask_ + _size_ |
| 41 | +# _index_ -> only for nested structures |
| 42 | +# |
| 43 | +# Values |
| 44 | +# slice -> slice |
| 45 | +# tuple(int, int) -> slice |
| 46 | +# list(int, int) -> slice |
| 47 | +# int -> int |
29 | 48 |
|
30 | 49 |
|
31 | 50 | def _is_descriptor(obj: typing.Any) -> bool:
|
@@ -134,7 +153,7 @@ def _get_start_index(src: typing.Tuple[typing.Any, IndexT]) -> int:
|
134 | 153 | return _get_index(src[1]).start # type: ignore
|
135 | 154 |
|
136 | 155 |
|
137 |
| -def _prepare_mapping(mapping: typing.Dict[str, typing.Union[IndexT, typing.Dict[str, typing.Any]]]) -> ResolvedMappingT: |
| 156 | +def _prepare_mapping(mapping: DeclaredMappingT) -> ResolvedMappingT: |
138 | 157 | """Check indexes for intersections.
|
139 | 158 |
|
140 | 159 | :type mapping: typing.Dict
|
@@ -291,7 +310,7 @@ def __new__( # type: ignore
|
291 | 310 | # Top level baseclass: cleanup
|
292 | 311 | for key in "_value_", "_size_", "_mask_", "_mapping_": # pragma: no cover
|
293 | 312 | classdict.pop(key, None)
|
294 |
| - return super(BinFieldMeta, mcs).__new__(mcs, name, bases, classdict) |
| 313 | + return super().__new__(mcs, name, bases, classdict) |
295 | 314 |
|
296 | 315 | meta_dict = {}
|
297 | 316 | meta_name = f"{name}Meta"
|
@@ -393,7 +412,7 @@ def __new__(
|
393 | 412 |
|
394 | 413 | sns["__slots__"] = () # No any new fields on instances
|
395 | 414 |
|
396 |
| - return super(SubMeta, smcs).__new__(smcs, sname, sbases, sns) # type: ignore |
| 415 | + return super().__new__(smcs, sname, sbases, sns) # type: ignore |
397 | 416 |
|
398 | 417 | # pylint: enable=bad-mcs-classmethod-argument
|
399 | 418 |
|
@@ -427,9 +446,7 @@ def makecls(
|
427 | 446 |
|
428 | 447 |
|
429 | 448 | # noinspection PyRedeclaration
|
430 |
| -BaseBinFieldMeta = type.__new__( # type: ignore # noqa: F811 |
431 |
| - BinFieldMeta, "BaseBinFieldMeta", (), {"__slots__": ()} |
432 |
| -) |
| 449 | +BaseBinFieldMeta = type.__new__(BinFieldMeta, "BaseBinFieldMeta", (), {"__slots__": ()}) # type: ignore # noqa: F811 |
433 | 450 |
|
434 | 451 |
|
435 | 452 | # noinspection PyRedeclaration,PyMissingConstructor
|
@@ -851,10 +868,10 @@ def __getitem__(self, item: KeyT) -> BinField:
|
851 | 868 | # Extract slice
|
852 | 869 | slc = slice(*idx["_index_"])
|
853 | 870 | # Build new _mapping_ dict
|
854 |
| - mapping = copy.deepcopy(idx) |
| 871 | + mapping: ResolvedMappingT = copy.deepcopy(idx) |
855 | 872 | del mapping["_index_"]
|
856 | 873 | # Get new val
|
857 |
| - return self._getslice_(slc, mapping=mapping, name=item) |
| 874 | + return self._getslice_(slc, mapping=mapping, name=item) # type: ignore |
858 | 875 |
|
859 | 876 | raise IndexError(item)
|
860 | 877 |
|
|
0 commit comments