Skip to content

Commit 46221b0

Browse files
committed
fix type annotations
1 parent 92fe659 commit 46221b0

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

.travis.yml

-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ _python:
1313
python: 3.7
1414
dist: xenial
1515
sudo: true
16-
- &pypy
17-
name: "PyPy"
18-
python: pypy
1916
- &pypy3
2017
name: "PyPy3"
2118
python: pypy3
@@ -91,8 +88,6 @@ jobs:
9188

9289
- stage: test
9390
<<: *python37
94-
- stage: test
95-
<<: *pypy
9691
- stage: test
9792
<<: *pypy3
9893

README.rst

-9
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ Python binfield implementation for binary data manipulation.
3636

3737
::
3838

39-
Python 2.7
40-
Python 3.4
41-
Python 3.5
4239
Python 3.6
4340
Python 3.7
44-
PyPy
4541
PyPy3
46-
Jyton 2.7
4742

4843
Usage
4944
=====
@@ -196,11 +191,7 @@ Test environments available:
196191
::
197192

198193
pep8
199-
py27
200-
py34
201-
py35
202194
py36
203-
pypy
204195
pypy3
205196
pylint
206197
docs

binfield/binfield.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@
2424

2525
KeyT = typing.Union[str, int, slice, typing.Tuple[int, int], typing.List[int]]
2626
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
2948

3049

3150
def _is_descriptor(obj: typing.Any) -> bool:
@@ -134,7 +153,7 @@ def _get_start_index(src: typing.Tuple[typing.Any, IndexT]) -> int:
134153
return _get_index(src[1]).start # type: ignore
135154

136155

137-
def _prepare_mapping(mapping: typing.Dict[str, typing.Union[IndexT, typing.Dict[str, typing.Any]]]) -> ResolvedMappingT:
156+
def _prepare_mapping(mapping: DeclaredMappingT) -> ResolvedMappingT:
138157
"""Check indexes for intersections.
139158
140159
:type mapping: typing.Dict
@@ -291,7 +310,7 @@ def __new__( # type: ignore
291310
# Top level baseclass: cleanup
292311
for key in "_value_", "_size_", "_mask_", "_mapping_": # pragma: no cover
293312
classdict.pop(key, None)
294-
return super(BinFieldMeta, mcs).__new__(mcs, name, bases, classdict)
313+
return super().__new__(mcs, name, bases, classdict)
295314

296315
meta_dict = {}
297316
meta_name = f"{name}Meta"
@@ -393,7 +412,7 @@ def __new__(
393412

394413
sns["__slots__"] = () # No any new fields on instances
395414

396-
return super(SubMeta, smcs).__new__(smcs, sname, sbases, sns) # type: ignore
415+
return super().__new__(smcs, sname, sbases, sns) # type: ignore
397416

398417
# pylint: enable=bad-mcs-classmethod-argument
399418

@@ -427,9 +446,7 @@ def makecls(
427446

428447

429448
# 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
433450

434451

435452
# noinspection PyRedeclaration,PyMissingConstructor
@@ -851,10 +868,10 @@ def __getitem__(self, item: KeyT) -> BinField:
851868
# Extract slice
852869
slc = slice(*idx["_index_"])
853870
# Build new _mapping_ dict
854-
mapping = copy.deepcopy(idx)
871+
mapping: ResolvedMappingT = copy.deepcopy(idx)
855872
del mapping["_index_"]
856873
# Get new val
857-
return self._getslice_(slc, mapping=mapping, name=item)
874+
return self._getslice_(slc, mapping=mapping, name=item) # type: ignore
858875

859876
raise IndexError(item)
860877

0 commit comments

Comments
 (0)