diff --git a/benchmarks/pmap.py b/benchmarks/pmap.py index f1f3c88..6d52d53 100644 --- a/benchmarks/pmap.py +++ b/benchmarks/pmap.py @@ -30,25 +30,25 @@ def _large_dict(): @Benchmarked(setup=_small_dict) def create_small_pmap(): for x in range(100): - _ = pmap(small_dict) + _ = pmap(small_dict) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_dict) def reference_create_small_dict(): for x in range(100): - _ = dict(small_dict) + _ = dict(small_dict) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_dict) def create_large_pmap(): for x in range(1): - _ = pmap(large_dict) + _ = pmap(large_dict) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_dict) def reference_create_large_dict(): for x in range(1): - _ = dict(large_dict) + _ = dict(large_dict) # type: ignore[reportUndefinedVariable] # ######################### Insert ###################### @@ -61,13 +61,13 @@ def _small_pmap(): @Benchmarked(setup=_small_pmap) def random_replace_small_pmap(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - small_pmap.set(x, x) + small_pmap.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_dict) def reference_random_replace_small_dict(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - small_dict[x] = x + small_dict[x] = x # type: ignore[reportUndefinedVariable] def _large_pmap(): @@ -77,18 +77,18 @@ def _large_pmap(): @Benchmarked(setup=_large_pmap) def random_replace_large_pmap(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - large_pmap.set(x, x) + large_pmap.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_dict) def reference_random_replace_large_dict(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - large_dict[x] = x + large_dict[x] = x # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_pmap) def random_replace_small_pmap_evolver(): - e = small_pmap.evolver() + e = small_pmap.evolver() # type: ignore[reportUndefinedVariable] for x in (9, 1, 4, 5, 7, 7, 3, 2): e[x] = x m = e.persistent() @@ -96,7 +96,7 @@ def random_replace_small_pmap_evolver(): @Benchmarked(setup=_large_pmap) def random_replace_large_pmap_evolver(): - e = large_pmap.evolver() + e = large_pmap.evolver() # type: ignore[reportUndefinedVariable] for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): e[x] = x m = e.persistent() @@ -105,25 +105,25 @@ def random_replace_large_pmap_evolver(): @Benchmarked(setup=_small_pmap) def random_insert_new_small_pmap(): for x in (19, 11, 14, 15, 17, 117, 13, 12): - small_pmap.set(x, x) + small_pmap.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_dict) def reference_random_insert_new_small_dict(): for x in (19, 11, 14, 15, 17, 117, 13, 12): - small_dict[x] = x + small_dict[x] = x # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_pmap) def random_insert_new_large_pmap(): for x in (100999, 100111, 10074, 1001233, 1006, 1001997, 100400, 1001000): - large_pmap.set(x, x) + large_pmap.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_dict) def reference_random_insert_new_large_dict(): for x in (100999, 100111, 10074, 1001233, 1006, 1001997, 100400, 1001000): - large_dict[x] = x + large_dict[x] = x # type: ignore[reportUndefinedVariable] # ################## Read ######################## @@ -131,38 +131,38 @@ def reference_random_insert_new_large_dict(): @Benchmarked(setup=_small_pmap) def random_read_small_pmap(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - y = small_pmap[x] + y = small_pmap[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_dict) def reference_random_read_small_dict(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - y = small_dict[x] + y = small_dict[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_pmap) def random_read_large_native_pvector(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - y = large_pmap[x] + y = large_pmap[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_dict) def reference_random_read_large_list(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - y = large_dict[x] + y = large_dict[x] # type: ignore[reportUndefinedVariable] # #################### Iteration ######################### @Benchmarked(setup=_large_pmap) def iteration_large_pmap(): - for k in large_pmap: + for k in large_pmap: # type: ignore[reportUndefinedVariable] pass @Benchmarked(setup=_large_dict) def reference_iteration_large_dict(): - for k in large_dict: + for k in large_dict: # type: ignore[reportUndefinedVariable] pass @@ -215,54 +215,54 @@ def _equal_pmaps_same_bucket_size_different_insertion_order(): @Benchmarked(setup=_large_pmap) def compare_same_pmap(): - large_pmap == large_pmap + large_pmap == large_pmap # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_large_dict) def reference_compare_same_dict(): - large_dict == large_dict + large_dict == large_dict # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_equal_pmaps) def compare_equal_pmaps(): - pmap1 == pmap2 + pmap1 == pmap2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_equal_dicts) def reference_compare_equal_dicts(): - dict1 == dict2 + dict1 == dict2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_equal_pmap_and_dict) def compare_equal_pmap_and_dict(): - pmap1 == dict1 + pmap1 == dict1 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_equal_pmaps_same_bucket_size_different_insertion_order) def compare_equal_pmaps_different_insertion_order(): - pmap1 == pmap2 + pmap1 == pmap2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_equal_pmaps_different_bucket_size) def compare_equal_pmaps_different_bucket_size(): - pmap1 == pmap2 + pmap1 == pmap2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_different_pmaps_same_size) def compare_different_pmaps_same_size(): - pmap1 == pmap2 + pmap1 == pmap2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_different_dicts_same_size) def reference_compare_different_dicts_same_size(): - dict1 == dict2 + dict1 == dict2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_different_pmaps_different_size) def compare_different_pmaps_different_size(): - pmap1 == pmap2 + pmap1 == pmap2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] @Benchmarked(setup=_different_dicts_different_size) def reference_compare_different_dicts_different_size(): - dict1 == dict2 + dict1 == dict2 # type: ignore[reportUndefinedVariable,reportUnusedExpression] diff --git a/benchmarks/pvector.py b/benchmarks/pvector.py index 04239a2..716c765 100644 --- a/benchmarks/pvector.py +++ b/benchmarks/pvector.py @@ -11,12 +11,12 @@ def __init__(self, scale=1, *args, **kwargs): @Benchmarked() def create_empty_native_pvector(): for x in range(1000): - _ = _pvector() + _ = _pvector() # type: ignore[reportCallIssue] @Benchmarked() def create_empty_python_pvector(): for x in range(1000): - _ = _pvector() + _ = _pvector() # type: ignore[reportCallIssue] @Benchmarked() def reference_create_empty_list(): @@ -32,63 +32,63 @@ def _large_list(): @Benchmarked(setup=_small_list) def create_small_native_pvector(): for x in range(100): - _ = _pvector(small_list) + _ = _pvector(small_list) # type: ignore[reportCallIssue,reportUndefinedVariable] @Benchmarked(setup=_small_list) def create_small_python_pvector(): for x in range(100): - _ = _pvector(small_list) + _ = _pvector(small_list) # type: ignore[reportCallIssue,reportUndefinedVariable] @Benchmarked(setup=_small_list) def reference_create_small_list(): for x in range(100): - _ = list(small_list) + _ = list(small_list) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_list) def create_large_native_pvector(): for x in range(10): - _ = _pvector(large_list) + _ = _pvector(large_list) # type: ignore[reportCallIssue,reportUndefinedVariable] @Benchmarked(setup=_large_list) def create_large_python_pvector(): for x in range(10): - _ = _pvector(large_list) + _ = _pvector(large_list) # type: ignore[reportCallIssue,reportUndefinedVariable] @Benchmarked(setup=_large_list) def reference_create_large_list(): for x in range(10): - _ = list(large_list) + _ = list(large_list) # type: ignore[reportUndefinedVariable] ####################### Append ##################### @Benchmarked() -def append_native_pvector(): - v = _pvector() +def append_native_pvector(): # type: ignore[reportRedeclaration] + v = _pvector() # type: ignore[reportCallIssue] for x in range(100): v = v.append(x) @Benchmarked() -def append_python_pvector(): - v = _pvector() +def append_python_pvector(): # type: ignore[reportRedeclaration] + v = _pvector() # type: ignore[reportCallIssue] for x in range(100): v = v.append(x) @Benchmarked() -def reference_append_list(): +def reference_append_list(): # type: ignore[reportRedeclaration] l = [] for x in range(100): l.append(x) @Benchmarked() def append_native_pvector(): - v = _pvector() + v = _pvector() # type: ignore[reportCallIssue] for x in range(100): v = v.append(x) @Benchmarked() def append_python_pvector(): - v = _pvector() + v = _pvector() # type: ignore[reportCallIssue] for x in range(100): v = v.append(x) @@ -102,60 +102,60 @@ def reference_append_list(): ######################### Insert ###################### def _small_native_vector(): - small_native_vector = _pvector(range(10)) + small_native_vector = _pvector(range(10)) # type: ignore[reportCallIssue] def _small_python_vector(): - small_python_vector = _pvector(range(10)) + small_python_vector = _pvector(range(10)) # type: ignore[reportCallIssue] @Benchmarked(setup=_small_native_vector) def random_insert_small_native_pvector(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - small_native_vector.set(x, x) + small_native_vector.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_python_vector) def random_insert_small_python_pvector(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - small_python_vector.set(x, x) + small_python_vector.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_list) def reference_random_insert_small_list(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - small_list[x] = x + small_list[x] = x # type: ignore[reportUndefinedVariable] def _large_native_vector(): - large_native_vector = _pvector(range(2000)) + large_native_vector = _pvector(range(2000)) # type: ignore[reportCallIssue] def _large_python_vector(): - large_python_vector = _pvector(range(2000)) + large_python_vector = _pvector(range(2000)) # type: ignore[reportCallIssue] @Benchmarked(setup=_large_native_vector) def random_insert_large_native_pvector(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - large_native_vector.set(x, x) + large_native_vector.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_python_vector) def random_insert_large_python_pvector(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - large_python_vector.set(x, x) + large_python_vector.set(x, x) # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_list) def reference_random_insert_large_list(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - large_list[x] = x + large_list[x] = x # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_native_vector) def random_insert_small_native_pvector_evolver(): - e = small_native_vector.evolver() + e = small_native_vector.evolver() # type: ignore[reportUndefinedVariable] for x in (9, 1, 4, 5, 7, 7, 3, 2): e[x] = x v = e.persistent() @@ -163,15 +163,15 @@ def random_insert_small_native_pvector_evolver(): @Benchmarked(setup=_small_python_vector) def random_insert_small_python_pvector_evolver(): - e = small_python_vector.evolver() + e = small_python_vector.evolver() # type: ignore[reportUndefinedVariable] for x in (9, 1, 4, 5, 7, 7, 3, 2): e[x] = x v = e.persistent() @Benchmarked(setup=_large_native_vector) -def random_insert_large_native_pvector_evolver(): - e = large_native_vector.evolver() +def random_insert_large_native_pvector_evolver(): # type: ignore[reportRedeclaration] + e = large_native_vector.evolver() # type: ignore[reportUndefinedVariable] for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): e[x] = x v = e.persistent() @@ -179,7 +179,7 @@ def random_insert_large_native_pvector_evolver(): @Benchmarked(setup=_large_python_vector) def random_insert_large_native_pvector_evolver(): - e = large_python_vector.evolver() + e = large_python_vector.evolver() # type: ignore[reportUndefinedVariable] for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): e[x] = x v = e.persistent() @@ -189,52 +189,52 @@ def random_insert_large_native_pvector_evolver(): @Benchmarked(setup=_small_native_vector) def random_read_small_native_pvector(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - y = small_native_vector[x] + y = small_native_vector[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_python_vector) def random_read_small_python_pvector(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - y = small_python_vector[x] + y = small_python_vector[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_small_list) def reference_random_read_small_list(): for x in (9, 1, 4, 5, 7, 7, 3, 2): - y = small_list[x] + y = small_list[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_native_vector) def random_read_large_native_pvector(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - y = large_native_vector[x] + y = large_native_vector[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_python_vector) def random_read_large_python_pvector(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - y = large_python_vector[x] + y = large_python_vector[x] # type: ignore[reportUndefinedVariable] @Benchmarked(setup=_large_list) def reference_random_read_large_list(): for x in (999, 111, 74, 1233, 6, 1997, 400, 1000): - y = large_list[x] + y = large_list[x] # type: ignore[reportUndefinedVariable] #################### Iteration ######################### @Benchmarked(setup=_large_native_vector) def iteration_large_native_pvector(): - for x in large_native_vector: + for x in large_native_vector: # type: ignore[reportUndefinedVariable] pass @Benchmarked(setup=_large_python_vector) def iteration_large_python_pvector(): - for x in large_python_vector: + for x in large_python_vector: # type: ignore[reportUndefinedVariable] pass @Benchmarked(setup=_large_list) def reference_iteration_large_list(): - for x in large_list: + for x in large_list: # type: ignore[reportUndefinedVariable] pass \ No newline at end of file diff --git a/pyrsistent/__init__.pyi b/pyrsistent/__init__.pyi index 5909f79..ac2604b 100644 --- a/pyrsistent/__init__.pyi +++ b/pyrsistent/__init__.pyi @@ -46,7 +46,7 @@ VT = TypeVar('VT') def pmap(initial: Union[Mapping[KT, VT], Iterable[Tuple[KT, VT]]] = {}, pre_size: int = 0) -> PMap[KT, VT]: ... def m(**kwargs: VT) -> PMap[str, VT]: ... -def pvector(iterable: Iterable[T] = ...) -> PVector[T]: ... +def pvector(iterable: Iterable[T] = ...) -> PVector[T]: ... # type: ignore[reportGeneralTypeIssues] def v(*iterable: T) -> PVector[T]: ... def pset(iterable: Iterable[T] = (), pre_size: int = 8) -> PSet[T]: ... @@ -151,8 +151,8 @@ class PRecord(PMap[AnyStr, Any]): ignore_extra: bool = False, ) -> T_PRecord: ... # This is OK because T_PRecord is a concrete type - def discard(self: T_PRecord, key: KT) -> T_PRecord: ... - def remove(self: T_PRecord, key: KT) -> T_PRecord: ... + def discard(self: T_PRecord, key: KT) -> T_PRecord: ... # type: ignore[reportGeneralTypeIssues] + def remove(self: T_PRecord, key: KT) -> T_PRecord: ... # type: ignore[reportGeneralTypeIssues] def serialize(self, format: Optional[Any] = ...) -> MutableMapping: ... @@ -161,9 +161,9 @@ class PRecord(PMap[AnyStr, Any]): # class. First of all it accepts key-value pairs. Second it accepts multiple key-value # pairs to perform one, atomic, update of multiple fields. @overload - def set(self, key: KT, val: VT) -> Any: ... + def set(self, key: KT, val: VT) -> Any: ... # type: ignore[reportGeneralTypeIssues] @overload - def set(self, **kwargs: VT) -> Any: ... + def set(self, **kwargs: VT) -> Any: ... # type: ignore[reportGeneralTypeIssues] def immutable( members: Union[str, Iterable[str]] = '', diff --git a/pyrsistent/_checked_types.py b/pyrsistent/_checked_types.py index 48446e5..523f6b4 100644 --- a/pyrsistent/_checked_types.py +++ b/pyrsistent/_checked_types.py @@ -270,7 +270,7 @@ def _checked_type_create(cls, source_data, _factory_fields=None, ignore_extra=Fa types = get_types(cls._checked_types) checked_type = next((t for t in types if issubclass(t, CheckedType)), None) if checked_type: - return cls([checked_type.create(data, ignore_extra=ignore_extra) + return cls([checked_type.create(data, ignore_extra=ignore_extra) # type: ignore[reportCallIssue] if not any(isinstance(data, t) for t in types) else data for data in source_data]) @@ -296,22 +296,22 @@ def __new__(cls, initial=()): return CheckedPVector.Evolver(cls, python_pvector()).extend(initial).persistent() - def set(self, key, value): + def set(self, key, value): # type: ignore[reportGeneralTypeIssues] return self.evolver().set(key, value).persistent() def append(self, val): return self.evolver().append(val).persistent() - def extend(self, it): + def extend(self, it): # type: ignore[reportGeneralTypeIssues] return self.evolver().extend(it).persistent() - create = classmethod(_checked_type_create) + create = classmethod(_checked_type_create) # type: ignore[reportGeneralTypeIssues] def serialize(self, format=None): - serializer = self.__serializer__ + serializer = self.__serializer__ # type: ignore[reportGeneralTypeIssues] return list(serializer(format, v) for v in self) - def __reduce__(self): + def __reduce__(self): # type: ignore[reportGeneralTypeIssues] # Pickling support return _restore_pickle, (self.__class__, list(self),) @@ -332,11 +332,11 @@ def __setitem__(self, key, value): self._check([value]) return super(CheckedPVector.Evolver, self).__setitem__(key, value) - def append(self, elem): + def append(self, elem): # type: ignore[reportGeneralTypeIssues] self._check([elem]) return super(CheckedPVector.Evolver, self).append(elem) - def extend(self, it): + def extend(self, it): # type: ignore[reportGeneralTypeIssues] it = list(it) self._check(it) return super(CheckedPVector.Evolver, self).extend(it) @@ -393,12 +393,12 @@ def __str__(self): return self.__repr__() def serialize(self, format=None): - serializer = self.__serializer__ + serializer = self.__serializer__ # type: ignore[reportGeneralTypeIssues] return set(serializer(format, v) for v in self) - create = classmethod(_checked_type_create) + create = classmethod(_checked_type_create) # type: ignore[reportGeneralTypeIssues] - def __reduce__(self): + def __reduce__(self): # type: ignore[reportGeneralTypeIssues] # Pickling support return _restore_pickle, (self.__class__, list(self),) @@ -504,9 +504,9 @@ def create(cls, source_data, _factory_fields=None): # Recursively apply create methods of checked types if the types of the supplied data # does not match any of the valid types. - key_types = get_types(cls._checked_key_types) + key_types = get_types(cls._checked_key_types) # type: ignore[reportGeneralTypeIssues] checked_key_type = next((t for t in key_types if issubclass(t, CheckedType)), None) - value_types = get_types(cls._checked_value_types) + value_types = get_types(cls._checked_value_types) # type: ignore[reportGeneralTypeIssues] checked_value_type = next((t for t in value_types if issubclass(t, CheckedType)), None) if checked_key_type or checked_value_type: @@ -516,7 +516,7 @@ def create(cls, source_data, _factory_fields=None): return cls(source_data) - def __reduce__(self): + def __reduce__(self): # type: ignore[reportGeneralTypeIssues] # Pickling support return _restore_pickle, (self.__class__, dict(self),) @@ -528,8 +528,8 @@ def __init__(self, destination_class, original_map): self._destination_class = destination_class self._invariant_errors = [] - def set(self, key, value): - _check_types([key], self._destination_class._checked_key_types, self._destination_class, CheckedKeyTypeError) + def set(self, key, value): # type: ignore[reportGeneralTypeIssues] + _check_types([key], self._destination_class._checked_key_types, self._destination_class, CheckedKeyTypeError) # type: ignore[reportGeneralTypeIssues] _check_types([value], self._destination_class._checked_value_types, self._destination_class) self._invariant_errors.extend(data for valid, data in (invariant(key, value) for invariant in self._destination_class._checked_invariants) diff --git a/pyrsistent/_field_common.py b/pyrsistent/_field_common.py index 508dd2f..635e12f 100644 --- a/pyrsistent/_field_common.py +++ b/pyrsistent/_field_common.py @@ -293,13 +293,13 @@ class TheMap(CheckedPMap): __key_type__ = key_type __value_type__ = value_type - def __reduce__(self): + def __reduce__(self): # type: ignore[reportGeneralTypeIssues] return (_restore_pmap_field_pickle, (self.__key_type__, self.__value_type__, dict(self))) TheMap.__name__ = "{0}To{1}PMap".format( - _types_to_names(TheMap._checked_key_types), - _types_to_names(TheMap._checked_value_types)) + _types_to_names(TheMap._checked_key_types), # type: ignore[reportGeneralTypeIssues] + _types_to_names(TheMap._checked_value_types)) # type: ignore[reportGeneralTypeIssues] _pmap_field_types[key_type, value_type] = TheMap return TheMap @@ -325,7 +325,7 @@ def factory(argument): else: return TheMap.create(argument) else: - factory = TheMap.create + factory = TheMap.create # type: ignore[reportGeneralTypeIssues] return field(mandatory=True, initial=TheMap(), type=optional_type(TheMap) if optional else TheMap, diff --git a/pyrsistent/_helpers.py b/pyrsistent/_helpers.py index b44bfc5..9d8f9c7 100644 --- a/pyrsistent/_helpers.py +++ b/pyrsistent/_helpers.py @@ -39,7 +39,7 @@ def freeze(o, strict=True): return pmap({k: freeze(v, strict) for k, v in o.items()}) if typ is list or (strict and isinstance(o, PVector)): curried_freeze = lambda x: freeze(x, strict) - return pvector(map(curried_freeze, o)) + return pvector(map(curried_freeze, o)) # type: ignore[reportGeneralTypeIssues] if typ is tuple: curried_freeze = lambda x: freeze(x, strict) return tuple(map(curried_freeze, o)) @@ -74,7 +74,7 @@ def thaw(o, strict=True): typ = type(o) if isinstance(o, PVector) or (strict and typ is list): curried_thaw = lambda x: thaw(x, strict) - return list(map(curried_thaw, o)) + return list(map(curried_thaw, o)) # type: ignore[reportGeneralTypeIssues] if isinstance(o, PMap) or (strict and typ is dict): return {k: thaw(v, strict) for k, v in o.items()} if typ is tuple: @@ -96,6 +96,6 @@ def mutant(fn): """ @wraps(fn) def inner_f(*args, **kwargs): - return freeze(fn(*[freeze(e) for e in args], **dict(freeze(item) for item in kwargs.items()))) + return freeze(fn(*[freeze(e) for e in args], **dict(freeze(item) for item in kwargs.items()))) # type: ignore[reportCallIssue] return inner_f diff --git a/pyrsistent/_pbag.py b/pyrsistent/_pbag.py index 50001f1..70340dd 100644 --- a/pyrsistent/_pbag.py +++ b/pyrsistent/_pbag.py @@ -233,8 +233,8 @@ def __hash__(self): return hash(self._counts) -Container.register(PBag) -Iterable.register(PBag) +Container.register(PBag) # type: ignore[reportGeneralTypeIssues] +Iterable.register(PBag) # type: ignore[reportGeneralTypeIssues] Sized.register(PBag) Hashable.register(PBag) diff --git a/pyrsistent/_pclass.py b/pyrsistent/_pclass.py index fd31a95..85f19cb 100644 --- a/pyrsistent/_pclass.py +++ b/pyrsistent/_pclass.py @@ -49,7 +49,7 @@ def __new__(cls, **kwargs): # Support *args? ignore_extra = kwargs.pop('ignore_extra', None) missing_fields = [] invariant_errors = [] - for name, field in cls._pclass_fields.items(): + for name, field in cls._pclass_fields.items(): # type: ignore[reportGeneralTypeIssues] if name in kwargs: if factory_fields is None or name in factory_fields: if is_field_ignore_extra_complaint(PClass, field, ignore_extra): @@ -74,7 +74,7 @@ def __new__(cls, **kwargs): # Support *args? raise AttributeError("'{0}' are not among the specified fields for {1}".format( ', '.join(kwargs), cls.__name__)) - check_global_invariants(result, cls._pclass_invariants) + check_global_invariants(result, cls._pclass_invariants) # type: ignore[reportGeneralTypeIssues] result._pclass_frozen = True return result @@ -103,7 +103,7 @@ def set(self, *args, **kwargs): factory_fields = set(kwargs) - for key in self._pclass_fields: + for key in self._pclass_fields: # type: ignore[reportGeneralTypeIssues] if key not in kwargs: value = getattr(self, key, _MISSING_VALUE) if value is not _MISSING_VALUE: @@ -112,7 +112,7 @@ def set(self, *args, **kwargs): return self.__class__(_factory_fields=factory_fields, **kwargs) @classmethod - def create(cls, kwargs, _factory_fields=None, ignore_extra=False): + def create(cls, kwargs, _factory_fields=None, ignore_extra=False): # type: ignore[reportGeneralTypeIssues] """ Factory method. Will create a new PClass of the current type and assign the values specified in kwargs. @@ -124,7 +124,7 @@ def create(cls, kwargs, _factory_fields=None, ignore_extra=False): return kwargs if ignore_extra: - kwargs = {k: kwargs[k] for k in cls._pclass_fields if k in kwargs} + kwargs = {k: kwargs[k] for k in cls._pclass_fields if k in kwargs} # type: ignore[reportGeneralTypeIssues] return cls(_factory_fields=_factory_fields, ignore_extra=ignore_extra, **kwargs) @@ -134,10 +134,10 @@ def serialize(self, format=None): such have been supplied. """ result = {} - for name in self._pclass_fields: + for name in self._pclass_fields: # type: ignore[reportGeneralTypeIssues] value = getattr(self, name, _MISSING_VALUE) if value is not _MISSING_VALUE: - result[name] = serialize(self._pclass_fields[name].serializer, format, value) + result[name] = serialize(self._pclass_fields[name].serializer, format, value) # type: ignore[reportGeneralTypeIssues] return result @@ -152,7 +152,7 @@ def transform(self, *transformations): def __eq__(self, other): if isinstance(other, self.__class__): - for name in self._pclass_fields: + for name in self._pclass_fields: # type: ignore[reportGeneralTypeIssues] if getattr(self, name, _MISSING_VALUE) != getattr(other, name, _MISSING_VALUE): return False @@ -165,7 +165,7 @@ def __ne__(self, other): def __hash__(self): # May want to optimize this by caching the hash somehow - return hash(tuple((key, getattr(self, key, _MISSING_VALUE)) for key in self._pclass_fields)) + return hash(tuple((key, getattr(self, key, _MISSING_VALUE)) for key in self._pclass_fields)) # type: ignore[reportGeneralTypeIssues] def __setattr__(self, key, value): if getattr(self, '_pclass_frozen', False): @@ -178,7 +178,7 @@ def __delattr__(self, key): def _to_dict(self): result = {} - for key in self._pclass_fields: + for key in self._pclass_fields: # type: ignore[reportGeneralTypeIssues] value = getattr(self, key, _MISSING_VALUE) if value is not _MISSING_VALUE: result[key] = value @@ -191,7 +191,7 @@ def __repr__(self): def __reduce__(self): # Pickling support - data = dict((key, getattr(self, key)) for key in self._pclass_fields if hasattr(self, key)) + data = dict((key, getattr(self, key)) for key in self._pclass_fields if hasattr(self, key)) # type: ignore[reportGeneralTypeIssues] return _restore_pickle, (self.__class__, data,) def evolver(self): diff --git a/pyrsistent/_pdeque.py b/pyrsistent/_pdeque.py index 0f25936..1d389f6 100644 --- a/pyrsistent/_pdeque.py +++ b/pyrsistent/_pdeque.py @@ -334,19 +334,19 @@ def __getitem__(self, index): if not isinstance(index, Integral): raise TypeError("'%s' object cannot be interpreted as an index" % type(index).__name__) - if index >= 0: - return self.popleft(index).left + if index >= 0: # type: ignore[reportOperatorIssue] + return self.popleft(index).left # type: ignore[reportGeneralTypeIssues] shifted = len(self) + index - if shifted < 0: + if shifted < 0: # type: ignore[reportOperatorIssue] raise IndexError( "pdeque index {0} out of range {1}".format(index, len(self)), ) - return self.popleft(shifted).left + return self.popleft(shifted).left # type: ignore[reportGeneralTypeIssues] index = Sequence.index -Sequence.register(PDeque) +Sequence.register(PDeque) # type: ignore[reportGeneralTypeIssues] Hashable.register(PDeque) diff --git a/pyrsistent/_plist.py b/pyrsistent/_plist.py index 322e15d..96dfa9d 100644 --- a/pyrsistent/_plist.py +++ b/pyrsistent/_plist.py @@ -103,8 +103,8 @@ def reverse(self): result = plist() head = self while head: - result = result.cons(head.first) - head = head.rest + result = result.cons(head.first) # type: ignore[reportGeneralTypeIssues] + head = head.rest # type: ignore[reportGeneralTypeIssues] return result __reversed__ = reverse @@ -121,8 +121,8 @@ def split(self, index): right_list = self i = 0 while right_list and i < index: - lb.append_elem(right_list.first) - right_list = right_list.rest + lb.append_elem(right_list.first) # type: ignore[reportGeneralTypeIssues] + right_list = right_list.rest # type: ignore[reportGeneralTypeIssues] i += 1 if not right_list: @@ -134,8 +134,8 @@ def split(self, index): def __iter__(self): li = self while li: - yield li.first - li = li.rest + yield li.first # type: ignore[reportGeneralTypeIssues] + li = li.rest # type: ignore[reportGeneralTypeIssues] def __lt__(self, other): if not isinstance(other, _PListBase): @@ -155,10 +155,10 @@ def __eq__(self, other): self_head = self other_head = other while self_head and other_head: - if not self_head.first == other_head.first: + if not self_head.first == other_head.first: # type: ignore[reportGeneralTypeIssues] return False - self_head = self_head.rest - other_head = other_head.rest + self_head = self_head.rest # type: ignore[reportGeneralTypeIssues] + other_head = other_head.rest # type: ignore[reportGeneralTypeIssues] return not self_head and not other_head @@ -181,7 +181,7 @@ def __getitem__(self, index): index += len(self) try: - return self._drop(index).first + return self._drop(index).first # type: ignore[reportGeneralTypeIssues] except AttributeError as e: raise IndexError("PList index out of range") from e @@ -191,7 +191,7 @@ def _drop(self, count): head = self while count > 0: - head = head.rest + head = head.rest # type: ignore[reportGeneralTypeIssues] count -= 1 return head @@ -213,11 +213,11 @@ def remove(self, elem): builder = _PListBuilder() head = self while head: - if head.first == elem: - return builder.append_plist(head.rest) + if head.first == elem: # type: ignore[reportGeneralTypeIssues] + return builder.append_plist(head.rest) # type: ignore[reportGeneralTypeIssues] - builder.append_elem(head.first) - head = head.rest + builder.append_elem(head.first) # type: ignore[reportGeneralTypeIssues] + head = head.rest # type: ignore[reportGeneralTypeIssues] raise ValueError('{0} not found in PList'.format(elem)) @@ -262,7 +262,7 @@ def __bool__(self): __nonzero__ = __bool__ -Sequence.register(PList) +Sequence.register(PList) # type: ignore[reportGeneralTypeIssues] Hashable.register(PList) @@ -282,7 +282,7 @@ def rest(self): return self -Sequence.register(_EmptyPList) +Sequence.register(_EmptyPList) # type: ignore[reportGeneralTypeIssues] Hashable.register(_EmptyPList) _EMPTY_PLIST = _EmptyPList() diff --git a/pyrsistent/_pmap.py b/pyrsistent/_pmap.py index 0d82c43..ea68184 100644 --- a/pyrsistent/_pmap.py +++ b/pyrsistent/_pmap.py @@ -36,7 +36,7 @@ def __init__(self, m): object.__setattr__(self, '_map', m) def __len__(self): - return len(self._map) + return len(self._map) # type: ignore[reportGeneralTypeIssues] def __setattr__(self, k, v): raise TypeError("%s is immutable" % (type(self),)) @@ -57,10 +57,10 @@ class PMapValues(PMapView): should generally be a `PMap` object. """ def __iter__(self): - return self._map.itervalues() + return self._map.itervalues() # type: ignore[reportGeneralTypeIssues] def __contains__(self, arg): - return arg in self._map.itervalues() + return arg in self._map.itervalues() # type: ignore[reportGeneralTypeIssues] # The str and repr methods imitate the dict_view style currently. def __str__(self): @@ -88,12 +88,12 @@ class PMapItems(PMapView): should generally be a `PMap` object. """ def __iter__(self): - return self._map.iteritems() + return self._map.iteritems() # type: ignore[reportGeneralTypeIssues] def __contains__(self, arg): try: (k,v) = arg except Exception: return False - return k in self._map and self._map[k] == v + return k in self._map and self._map[k] == v # type: ignore[reportGeneralTypeIssues] # The str and repr methods mitate the dict_view style currently. def __str__(self): @@ -105,7 +105,7 @@ def __repr__(self): def __eq__(self, x): if x is self: return True elif not isinstance(x, type(self)): return False - else: return self._map == x._map + else: return self._map == x._map # type: ignore[reportGeneralTypeIssues] class PMap(Generic[KT, VT_co]): """ @@ -149,8 +149,8 @@ class PMap(Generic[KT, VT_co]): def __new__(cls, size, buckets): self = super(PMap, cls).__new__(cls) - self._size = size - self._buckets = buckets + self._size = size # type: ignore[reportGeneralTypeIssues] + self._buckets = buckets # type: ignore[reportGeneralTypeIssues] return self @staticmethod @@ -446,9 +446,9 @@ def _reallocate(self): for k, v in chain.from_iterable(x for x in buckets if x): index = hash(k) % new_size if new_list[index]: - new_list[index].append((k, v)) + new_list[index].append((k, v)) # type: ignore[reportGeneralTypeIssues] else: - new_list[index] = [(k, v)] + new_list[index] = [(k, v)] # type: ignore[reportCallIssue] # A reallocation should always result in a dirty buckets evolver to avoid # possible loss of elements when doing the reallocation. @@ -518,7 +518,7 @@ def evolver(self): """ return self._Evolver(self) -Mapping.register(PMap) +Mapping.register(PMap) # type: ignore[reportGeneralTypeIssues] Hashable.register(PMap) @@ -549,7 +549,7 @@ def _turbo_mapping(initial, pre_size): if bucket: bucket.append((k, v)) else: - buckets[index] = [(k, v)] + buckets[index] = [(k, v)] # type: ignore[reportCallIssue] return PMap(len(initial), pvector().extend(buckets)) diff --git a/pyrsistent/_precord.py b/pyrsistent/_precord.py index 1ee8198..b657486 100644 --- a/pyrsistent/_precord.py +++ b/pyrsistent/_precord.py @@ -41,12 +41,12 @@ def __new__(cls, **kwargs): ignore_extra = kwargs.pop('_ignore_extra', False) initial_values = kwargs - if cls._precord_initial_values: + if cls._precord_initial_values: # type: ignore[reportGeneralTypeIssues] initial_values = dict((k, v() if callable(v) else v) - for k, v in cls._precord_initial_values.items()) + for k, v in cls._precord_initial_values.items()) # type: ignore[reportGeneralTypeIssues] initial_values.update(kwargs) - e = _PRecordEvolver(cls, pmap(pre_size=len(cls._precord_fields)), _factory_fields=factory_fields, _ignore_extra=ignore_extra) + e = _PRecordEvolver(cls, pmap(pre_size=len(cls._precord_fields)), _factory_fields=factory_fields, _ignore_extra=ignore_extra) # type: ignore[reportGeneralTypeIssues] for k, v in initial_values.items(): e[k] = v @@ -77,7 +77,7 @@ def __repr__(self): ', '.join('{0}={1}'.format(k, repr(v)) for k, v in self.items())) @classmethod - def create(cls, kwargs, _factory_fields=None, ignore_extra=False): + def create(cls, kwargs, _factory_fields=None, ignore_extra=False): # type: ignore[reportGeneralTypeIssues] """ Factory method. Will create a new PRecord of the current type and assign the values specified in kwargs. @@ -89,11 +89,11 @@ def create(cls, kwargs, _factory_fields=None, ignore_extra=False): return kwargs if ignore_extra: - kwargs = {k: kwargs[k] for k in cls._precord_fields if k in kwargs} + kwargs = {k: kwargs[k] for k in cls._precord_fields if k in kwargs} # type: ignore[reportGeneralTypeIssues] return cls(_factory_fields=_factory_fields, _ignore_extra=ignore_extra, **kwargs) - def __reduce__(self): + def __reduce__(self): # type: ignore[reportGeneralTypeIssues] # Pickling support return _restore_pickle, (self.__class__, dict(self),) @@ -119,7 +119,7 @@ def __init__(self, cls, original_pmap, _factory_fields=None, _ignore_extra=False def __setitem__(self, key, original_value): self.set(key, original_value) - def set(self, key, original_value): + def set(self, key, original_value): # type: ignore[reportGeneralTypeIssues] field = self._destination_cls._precord_fields.get(key) if field: if self._factory_fields is None or field in self._factory_fields: diff --git a/pyrsistent/_pset.py b/pyrsistent/_pset.py index 6247607..ec1ad81 100644 --- a/pyrsistent/_pset.py +++ b/pyrsistent/_pset.py @@ -32,17 +32,17 @@ class PSet(Generic[T_co]): def __new__(cls, m): self = super(PSet, cls).__new__(cls) - self._map = m + self._map = m # type: ignore[reportGeneralTypeIssues] return self def __contains__(self, element): - return element in self._map + return element in self._map # type: ignore[reportGeneralTypeIssues] def __iter__(self): - return iter(self._map) + return iter(self._map) # type: ignore[reportGeneralTypeIssues] def __len__(self): - return len(self._map) + return len(self._map) # type: ignore[reportGeneralTypeIssues] def __repr__(self): if not self: @@ -54,7 +54,7 @@ def __str__(self): return self.__repr__() def __hash__(self): - return hash(self._map) + return hash(self._map) # type: ignore[reportGeneralTypeIssues] def __reduce__(self): # Pickling support @@ -96,7 +96,7 @@ def remove(self, element): >>> s1.remove(2) pset([1]) """ - if element in self._map: + if element in self._map: # type: ignore[reportGeneralTypeIssues] return self.evolver().remove(element).persistent() raise KeyError("Element '%s' not present in PSet" % repr(element)) @@ -105,7 +105,7 @@ def discard(self, element): """ Return a new PSet with element removed. Returns itself if element is not present. """ - if element in self._map: + if element in self._map: # type: ignore[reportGeneralTypeIssues] return self.evolver().remove(element).persistent() return self @@ -196,7 +196,7 @@ def evolver(self): isdisjoint = Set.isdisjoint -Set.register(PSet) +Set.register(PSet) # type: ignore[reportGeneralTypeIssues] Hashable.register(PSet) _EMPTY_PSET = PSet(pmap()) diff --git a/pyrsistent/_pvector.py b/pyrsistent/_pvector.py index 51d8a22..758bf18 100644 --- a/pyrsistent/_pvector.py +++ b/pyrsistent/_pvector.py @@ -18,7 +18,7 @@ def _bitcount(val): def compare_pvector(v, other, operator): - return operator(v.tolist(), other.tolist() if isinstance(other, PVector) else other) + return operator(v.tolist(), other.tolist() if isinstance(other, PVector) else other) # type: ignore[reportGeneralTypeIssues] def _index_or_slice(index, stop): @@ -200,7 +200,7 @@ def __setitem__(self, index, val): if index < 0: index += self._count + len(self._extra_tail) - if 0 <= index < self._count: + if 0 <= index < self._count: # type: ignore[reportGeneralTypeIssues] node = self._cached_leafs.get(index >> SHIFT) if node: node[index & BIT_MASK] = val @@ -277,10 +277,10 @@ def set(self, i, val): if i < 0: i += self._count - if 0 <= i < self._count: - if i >= self._tail_offset: + if 0 <= i < self._count: # type: ignore[reportGeneralTypeIssues] + if i >= self._tail_offset: # type: ignore[reportGeneralTypeIssues] new_tail = list(self._tail) - new_tail[i & BIT_MASK] = val + new_tail[i & BIT_MASK] = val # type: ignore[reportGeneralTypeIssues] return PythonPVector(self._count, self._shift, self._root, new_tail) return PythonPVector(self._count, self._shift, self._do_set(self._shift, self._root, i, val), self._tail) @@ -493,7 +493,7 @@ def __mul__(self, times): """ @abstractmethod - def __hash__(self): + def __hash__(self): # type: ignore[reportGeneralTypeIssues] """ >>> v1 = v(1, 2, 3) >>> v2 = v(1, 2, 3) @@ -679,7 +679,7 @@ def remove(self, value): _EMPTY_PVECTOR = PythonPVector(0, SHIFT, [], []) PVector.register(PythonPVector) -Sequence.register(PVector) +Sequence.register(PVector) # type: ignore[reportGeneralTypeIssues] Hashable.register(PVector) def python_pvector(iterable=()): diff --git a/pyrsistent/_transformations.py b/pyrsistent/_transformations.py index 6ef747f..d12a051 100644 --- a/pyrsistent/_transformations.py +++ b/pyrsistent/_transformations.py @@ -103,16 +103,16 @@ def _get_keys_and_values(structure, key_spec): if signature is None: def _get_arity(f): - argspec = getfullargspec(f) + argspec = getfullargspec(f) # type: ignore[reportPossiblyUnboundVariable] return len(argspec.args) - len(argspec.defaults or ()) else: def _get_arity(f): return sum( 1 for p - in signature(f).parameters.values() - if p.default is Parameter.empty - and p.kind in (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD) + in signature(f).parameters.values() # type: ignore[reportOptionalCall] + if p.default is Parameter.empty # type: ignore[reportPossiblyUnboundVariable] + and p.kind in (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD) # type: ignore[reportPossiblyUnboundVariable] ) diff --git a/pyrsistent/typing.pyi b/pyrsistent/typing.pyi index 801dc70..2bb4ffa 100644 --- a/pyrsistent/typing.pyi +++ b/pyrsistent/typing.pyi @@ -229,7 +229,7 @@ class CheckedPMap(PMap[KT, VT]): class CheckedPVector(PVector[T]): __type__: Type[T] - def __new__(self, initial: Iterable[T] = ...) -> CheckedPVector: ... + def __new__(self, initial: Iterable[T] = ...) -> CheckedPVector: ... # type: ignore[reportSelfClsParameterName] @classmethod def create(cls, source_data: Iterable[T], _factory_fields: Any = ...) -> CheckedPVector[T]: ... def serialize(self, format: Optional[Any] = ...) -> List[T]: ... diff --git a/setup.py b/setup.py index 189a4ba..baf4e21 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ def build_extension(self, ext): ], scripts=[], ext_modules=extensions, - cmdclass={'build_ext': custom_build_ext}, + cmdclass={'build_ext': custom_build_ext}, # type: ignore[reportGeneralTypeIssues] packages=['pyrsistent'], package_data={'pyrsistent': ['py.typed', '__init__.pyi', 'typing.pyi']}, python_requires='>=3.8', diff --git a/tests/checked_map_test.py b/tests/checked_map_test.py index aae07ed..662cc18 100644 --- a/tests/checked_map_test.py +++ b/tests/checked_map_test.py @@ -127,8 +127,8 @@ class FloatVector(CheckedPVector): class VectorToSetMap(CheckedPMap): - __key_type__ = 'checked_map_test.FloatVector' - __value_type__ = 'checked_map_test.FloatSet' + __key_type__ = 'checked_map_test.FloatVector' # type: ignore[reportGeneralTypeIssues] + __value_type__ = 'checked_map_test.FloatSet' # type: ignore[reportGeneralTypeIssues] def test_type_check_with_string_specification(): diff --git a/tests/checked_vector_test.py b/tests/checked_vector_test.py index 88bd19e..deb228c 100644 --- a/tests/checked_vector_test.py +++ b/tests/checked_vector_test.py @@ -98,14 +98,14 @@ def test_create_with_instance_of_checked_pvector_returns_the_argument(): assert Naturals.create(x) is x class OptionalNaturals(CheckedPVector): - __type__ = optional(int) + __type__ = optional(int) # type: ignore[reportGeneralTypeIssues] __invariant__ = lambda value: (value is None or value >= 0, 'Negative value') def test_multiple_allowed_types(): assert list(OptionalNaturals([1, None, 3])) == [1, None, 3] class NaturalsVector(CheckedPVector): - __type__ = optional(Naturals) + __type__ = optional(Naturals) # type: ignore[reportGeneralTypeIssues] def test_create_of_nested_structure(): assert NaturalsVector([Naturals([1, 2]), Naturals([3, 4]), None]) ==\ @@ -154,7 +154,7 @@ class InvalidInvariant(CheckedPVector): def test_type_spec_must_be_type(): with pytest.raises(TypeError): class InvalidType(CheckedPVector): - __type__ = 1 + __type__ = 1 # type: ignore[reportGeneralTypeIssues] def test_repr(): x = Naturals([1, 2]) @@ -174,7 +174,7 @@ def test_pickling(): def test_multiple_optional_types(): class Numbers(CheckedPVector): - __type__ = optional(int, float) + __type__ = optional(int, float) # type: ignore[reportGeneralTypeIssues] numbers = Numbers([1, 2.5, None]) assert numbers.serialize() == [1, 2.5, None] @@ -184,7 +184,7 @@ class Numbers(CheckedPVector): class NaturalsVectorStr(CheckedPVector): - __type__ = 'checked_vector_test.Naturals' + __type__ = 'checked_vector_test.Naturals' # type: ignore[reportGeneralTypeIssues] def test_check_with_string_specification(): diff --git a/tests/class_test.py b/tests/class_test.py index def8dce..39aba60 100644 --- a/tests/class_test.py +++ b/tests/class_test.py @@ -20,7 +20,7 @@ class Hierarchy(PClass): class TypedContainerObj(PClass): map = pmap_field(str, str) - set = pset_field(str) + set = pset_field(str) # type: ignore[reportGeneralTypeIssues] vec = pvector_field(str) @@ -261,7 +261,7 @@ def test_evolver_supports_chained_set_and_remove(): def test_evolver_supports_dot_notation_for_setting_and_getting_elements(): e = Point(x=1, y=2).evolver() - e.x = 3 + e.x = 3 # type: ignore[reportGeneralTypeIssues] assert e.x == 3 assert e.persistent() == Point(x=3, y=2) @@ -315,11 +315,11 @@ class MultiInvariantGlobal(PClass): def test_inherited_global_invariants(): class Distant(object): def __invariant__(self): - return [(self.distant, "distant")] + return [(self.distant, "distant")] # type: ignore[reportGeneralTypeIssues] class Nearby(Distant): def __invariant__(self): - return [(self.nearby, "nearby")] + return [(self.nearby, "nearby")] # type: ignore[reportGeneralTypeIssues] class MultipleInvariantGlobal(Nearby, PClass): distant = field() @@ -438,7 +438,7 @@ def test_pickle_with_one_way_factory(): def test_evolver_with_one_way_factory(): thing = UniqueThing(id='cc65249a-56fe-4995-8719-ea02e124b234') ev = thing.evolver() - ev.x = 5 # necessary to prevent persistent() returning the original + ev.x = 5 # necessary to prevent persistent() returning the original # type: ignore[reportGeneralTypeIssues] assert ev.persistent() == UniqueThing(id=str(thing.id), x=5) diff --git a/tests/deque_test.py b/tests/deque_test.py index 7798a75..e24102d 100644 --- a/tests/deque_test.py +++ b/tests/deque_test.py @@ -19,7 +19,7 @@ def test_construction_with_maxlen(): def test_construction_with_invalid_maxlen(): with pytest.raises(TypeError): - pdeque([], maxlen='foo') + pdeque([], maxlen='foo') # type: ignore[reportGeneralTypeIssues] with pytest.raises(ValueError): pdeque([], maxlen=-3) @@ -198,7 +198,7 @@ def test_set_maxlen(): assert x.maxlen == 4 with pytest.raises(AttributeError): - x.maxlen = 5 + x.maxlen = 5 # type: ignore[reportGeneralTypeIssues] def test_comparison(): @@ -255,7 +255,7 @@ def test_indexing_out_of_range(): def test_indexing_invalid_type(): with pytest.raises(TypeError) as e: - pdeque([1, 2, 3])['foo'] + pdeque([1, 2, 3])['foo'] # type: ignore[reportCallIssue] assert 'cannot be interpreted' in str(e.value) diff --git a/tests/field_test.py b/tests/field_test.py index 176b64c..0725ffe 100644 --- a/tests/field_test.py +++ b/tests/field_test.py @@ -11,13 +11,13 @@ class ExampleEnum(Enum): def test_enum(): f = field(type=ExampleEnum) - assert ExampleEnum in f.type - assert len(f.type) == 1 + assert ExampleEnum in f.type # type: ignore[reportGeneralTypeIssues] + assert len(f.type) == 1 # type: ignore[reportGeneralTypeIssues] # This is meant to exercise `_seq_field`. def test_pvector_field_enum_type(): f = pvector_field(ExampleEnum) - assert len(f.type) == 1 - assert ExampleEnum is list(f.type)[0].__type__ + assert len(f.type) == 1 # type: ignore[reportGeneralTypeIssues] + assert ExampleEnum is list(f.type)[0].__type__ # type: ignore[reportGeneralTypeIssues] diff --git a/tests/freeze_test.py b/tests/freeze_test.py index 158cf5d..77f8f34 100644 --- a/tests/freeze_test.py +++ b/tests/freeze_test.py @@ -19,7 +19,7 @@ def test_freeze_dict(): def test_freeze_defaultdict(): test_dict = collections.defaultdict(dict) - test_dict['a'] = 'b' + test_dict['a'] = 'b' # type: ignore[reportGeneralTypeIssues] result = freeze(test_dict) assert result == m(a='b') assert type(freeze({'a': 'b'})) is type(m()) @@ -36,7 +36,7 @@ def test_freeze_recurse_in_dictionary_values(): def test_freeze_recurse_in_defaultdict_values(): test_dict = collections.defaultdict(dict) - test_dict['a'] = [1] + test_dict['a'] = [1] # type: ignore[reportGeneralTypeIssues] result = freeze(test_dict) assert result == m(a=v(1)) assert type(result['a']) is type(v()) @@ -73,7 +73,7 @@ def test_freeze_recurse_in_tuples(): def test_freeze_nonstrict_no_recurse_in_pmap_values(): input = {'a': m(b={'c': 1})} - result = freeze(input, strict=False) + result = freeze(input, strict=False) # type: ignore[reportGeneralTypeIssues] # PMap and PVector are == to their mutable equivalents assert result == input assert type(result) is type(m()) @@ -81,7 +81,7 @@ def test_freeze_nonstrict_no_recurse_in_pmap_values(): def test_freeze_nonstrict_no_recurse_in_pvectors(): input = [1, v(2, [3])] - result = freeze(input, strict=False) + result = freeze(input, strict=False) # type: ignore[reportGeneralTypeIssues] # PMap and PVector are == to their mutable equivalents assert result == input assert type(result) is type(v()) @@ -148,13 +148,13 @@ class R(PRecord): ## Thaw (weak) def test_thaw_non_strict_no_recurse_in_dict_values(): - result = thaw({'a': v(1, m(b=2))}, strict=False) + result = thaw({'a': v(1, m(b=2))}, strict=False) # type: ignore[reportGeneralTypeIssues] assert result == {'a': [1, {'b': 2}]} assert type(result['a']) is type(v()) assert type(result['a'][1]) is type(m()) def test_thaw_non_strict_no_recurse_in_lists(): - result = thaw(v(['a', m(b=1), v(2)]), strict=False) + result = thaw(v(['a', m(b=1), v(2)]), strict=False) # type: ignore[reportGeneralTypeIssues] assert result == [['a', {'b': 1}, [2]]] assert type(result[0][1]) is type(m()) diff --git a/tests/immutable_object_test.py b/tests/immutable_object_test.py index 11ff513..c0e8a0a 100644 --- a/tests/immutable_object_test.py +++ b/tests/immutable_object_test.py @@ -1,19 +1,19 @@ import pytest from pyrsistent import immutable -class Empty(immutable(verbose=True)): +class Empty(immutable(verbose=True)): # type: ignore[reportGeneralTypeIssues] pass -class Single(immutable('x')): +class Single(immutable('x')): # type: ignore[reportGeneralTypeIssues] pass -class FrozenMember(immutable('x, y_')): +class FrozenMember(immutable('x, y_')): # type: ignore[reportGeneralTypeIssues] pass -class DerivedWithNew(immutable(['x', 'y'])): +class DerivedWithNew(immutable(['x', 'y'])): # type: ignore[reportGeneralTypeIssues] def __new__(cls, x, y): return super(DerivedWithNew, cls).__new__(cls, x, y) diff --git a/tests/list_test.py b/tests/list_test.py index ccbd83b..e5074eb 100644 --- a/tests/list_test.py +++ b/tests/list_test.py @@ -28,7 +28,7 @@ def test_cons(): def test_cons_empty_list(): - assert plist().cons(0) == plist([0]) + assert plist().cons(0) == plist([0]) # type: ignore[reportGeneralTypeIssues] def test_truthiness(): @@ -144,8 +144,8 @@ def test_pickling_non_empty_list(): def test_comparison(): assert plist([1, 2]) < plist([1, 2, 3]) assert plist([2, 1]) > plist([1, 2, 3]) - assert plist() < plist([1]) - assert plist([1]) > plist() + assert plist() < plist([1]) # type: ignore[reportOperatorIssue] + assert plist([1]) > plist() # type: ignore[reportOperatorIssue] def test_comparison_with_other_type(): @@ -187,7 +187,7 @@ def test_remove_missing_element(): plist([1, 2]).remove(3) with pytest.raises(ValueError): - plist().remove(2) + plist().remove(2) # type: ignore[reportGeneralTypeIssues] def test_mcons(): diff --git a/tests/map_test.py b/tests/map_test.py index 391d23d..67b85c3 100644 --- a/tests/map_test.py +++ b/tests/map_test.py @@ -255,7 +255,7 @@ def test_addition(): def test_union_operator(): - assert m(x=1, y=2) | m(y=3, z=4) == m(x=1, y=3, z=4) + assert m(x=1, y=2) | m(y=3, z=4) == m(x=1, y=3, z=4) # type: ignore[reportOperatorIssue] def test_transform_base_case(): @@ -312,8 +312,8 @@ def test_hash_collision_is_correctly_resolved(): # Reuse existing structure when inserted element is the same assert map2.set(dummy1, 11) is map2 - map3 = map1.set('a', 22) - assert map3['a'] == 22 + map3 = map1.set('a', 22) # type: ignore[reportGeneralTypeIssues] + assert map3['a'] == 22 # type: ignore[reportGeneralTypeIssues] assert map3[dummy3] == 3 # Remove elements @@ -357,8 +357,8 @@ def test_iteration_with_many_elements(): # Throw in a couple of hash collision nodes to tests # those properly as well - init_dict[hash_dummy1] = 12345 - init_dict[hash_dummy2] = 54321 + init_dict[hash_dummy1] = 12345 # type: ignore[reportGeneralTypeIssues] + init_dict[hash_dummy2] = 54321 # type: ignore[reportGeneralTypeIssues] a_map = pmap(init_dict) actual_values = set() @@ -451,10 +451,10 @@ def test_evolver_set_with_reallocation_edge_case(): def test_evolver_remove_element(): e = m(a=1000, b=2000).evolver() - assert 'a' in e + assert 'a' in e # type: ignore[reportOperatorIssue] del e['a'] - assert 'a' not in e + assert 'a' not in e # type: ignore[reportOperatorIssue] def test_evolver_remove_element_not_present(): @@ -485,16 +485,16 @@ def test_dot_access_of_non_existing_element_raises_attribute_error(): def test_pmap_unorderable(): with pytest.raises(TypeError): - _ = m(a=1) < m(b=2) + _ = m(a=1) < m(b=2) # type: ignore[reportOperatorIssue] with pytest.raises(TypeError): - _ = m(a=1) <= m(b=2) + _ = m(a=1) <= m(b=2) # type: ignore[reportOperatorIssue] with pytest.raises(TypeError): - _ = m(a=1) > m(b=2) + _ = m(a=1) > m(b=2) # type: ignore[reportOperatorIssue] with pytest.raises(TypeError): - _ = m(a=1) >= m(b=2) + _ = m(a=1) >= m(b=2) # type: ignore[reportOperatorIssue] def test_supports_weakref(): diff --git a/tests/memory_profiling.py b/tests/memory_profiling.py index 6903652..a72358e 100644 --- a/tests/memory_profiling.py +++ b/tests/memory_profiling.py @@ -4,7 +4,7 @@ import inspect import sys import time -import memory_profiler +import memory_profiler # type: ignore[reportMissingImports] import vector_test from pyrsistent import pvector @@ -40,7 +40,7 @@ def profile_tests(): fn_args = inspect.getfullargspec(fn)[0] if 'pvector' in fn_args: print('Executing %s' % name) - result = memory_profiler.memory_usage((run_function, (fn,), {}), interval=.1) + result = memory_profiler.memory_usage((run_function, (fn,), {}), interval=.1) # type: ignore[reportGeneralTypeIssues] assert not detect_memory_leak(result), (name, result) diff --git a/tests/performance_run.py b/tests/performance_run.py index 28db9a3..061a1ab 100644 --- a/tests/performance_run.py +++ b/tests/performance_run.py @@ -204,7 +204,7 @@ def run_to_list(): try: before = time.time() - l1 = p._totuple() + l1 = p._totuple() # type: ignore[reportGeneralTypeIssues] print("Totuple: " + str(time.time() - before)) except: print("Totuple not implemented") @@ -247,8 +247,8 @@ def run_multiple_random_inserts(): print("Number of accesses: %s" % len(indices)) print("Number of elements in vector: %s" % max(indices)) - original = _pvector(range(max(indices) + 1)) - original2 = _pvector(range(max(indices) + 1)) + original = _pvector(range(max(indices) + 1)) # type: ignore[reportCallIssue] + original2 = _pvector(range(max(indices) + 1)) # type: ignore[reportCallIssue] # Using ordinary set start = time.time() diff --git a/tests/record_test.py b/tests/record_test.py index 95fc55b..80a87fe 100644 --- a/tests/record_test.py +++ b/tests/record_test.py @@ -22,7 +22,7 @@ class Hierarchy(PRecord): class RecordContainingContainers(PRecord): map = pmap_field(str, str) vec = pvector_field(str) - set = pset_field(str) + set = pset_field(str) # type: ignore[reportGeneralTypeIssues] class UniqueThing(PRecord): @@ -684,7 +684,7 @@ class Bar(PRecord): bar = pvector_field(Foo) data = Bar(bar=v(Foo(foo="foo"))) - Bar.create(data.serialize()) == data + Bar.create(data.serialize()) == data # type: ignore[reportUnusedExpression] def test_pmap_field_initial_value(): """ @@ -855,7 +855,7 @@ class Bar(PRecord): bar = pmap_field(str, Foo) data = Bar(bar=m(foo_key=Foo(foo="foo"))) - Bar.create(data.serialize()) == data + Bar.create(data.serialize()) == data # type: ignore[reportUnusedExpression] def test_supports_weakref(): diff --git a/tests/set_test.py b/tests/set_test.py index f605ee0..aaf8995 100644 --- a/tests/set_test.py +++ b/tests/set_test.py @@ -4,7 +4,7 @@ def test_key_is_tuple(): with pytest.raises(KeyError): - pset().remove((1,1)) + pset().remove((1,1)) # type: ignore[reportGeneralTypeIssues] def test_literalish_works(): assert s() is pset() diff --git a/tests/toolz_test.py b/tests/toolz_test.py index d145704..aca84c2 100644 --- a/tests/toolz_test.py +++ b/tests/toolz_test.py @@ -3,4 +3,4 @@ def test_get_in(): # This is not an extensive test. The doctest covers that fairly good though. - get_in(m(a=v(1, 2, 3)), ['m', 1]) == 2 + get_in(m(a=v(1, 2, 3)), ['m', 1]) == 2 # type: ignore[reportUnusedExpression] diff --git a/tox.ini b/tox.ini index 834a2ba..2daebe7 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ envlist = memorytest38 doctest38 coverage-py38 + typecheck [gh-actions] python = @@ -65,5 +66,13 @@ deps = pytest changedir = . commands = pytest --doctest-modules pyrsistent +[testenv:typecheck] +deps = + {[testenv]deps} + pyperform + pyright[nodejs] +commands = + pyright + [pytest] norecursedirs = build