summaryrefslogtreecommitdiffhomepage
path: root/libs/pyrsistent
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2024-03-03 12:15:23 -0500
committerGitHub <[email protected]>2024-03-03 12:15:23 -0500
commit03afeb347075381bcb7fd6036295c9fa4a90d2dc (patch)
tree7c5d72c973d2c8e4ade57391a1c9ad5e94903a46 /libs/pyrsistent
parent9ae684240b5bdd40a870d8122f0e380f8d03a187 (diff)
downloadbazarr-03afeb347075381bcb7fd6036295c9fa4a90d2dc.tar.gz
bazarr-03afeb347075381bcb7fd6036295c9fa4a90d2dc.zip
Updated multiple Python modules (now in libs and custom_libs directories) and React libraries
Diffstat (limited to 'libs/pyrsistent')
-rw-r--r--libs/pyrsistent/_checked_types.py11
-rw-r--r--libs/pyrsistent/_helpers.py4
-rw-r--r--libs/pyrsistent/_immutable.py8
-rw-r--r--libs/pyrsistent/_pbag.py5
-rw-r--r--libs/pyrsistent/_pdeque.py9
-rw-r--r--libs/pyrsistent/_plist.py5
-rw-r--r--libs/pyrsistent/_pmap.py17
-rw-r--r--libs/pyrsistent/_pset.py5
-rw-r--r--libs/pyrsistent/_pvector.py6
-rw-r--r--libs/pyrsistent/_transformations.py4
-rw-r--r--libs/pyrsistent/typing.py20
11 files changed, 63 insertions, 31 deletions
diff --git a/libs/pyrsistent/_checked_types.py b/libs/pyrsistent/_checked_types.py
index 8ab8c2a8c..48446e516 100644
--- a/libs/pyrsistent/_checked_types.py
+++ b/libs/pyrsistent/_checked_types.py
@@ -2,11 +2,16 @@ from enum import Enum
from abc import abstractmethod, ABCMeta
from collections.abc import Iterable
+from typing import TypeVar, Generic
from pyrsistent._pmap import PMap, pmap
from pyrsistent._pset import PSet, pset
from pyrsistent._pvector import PythonPVector, python_pvector
+T_co = TypeVar('T_co', covariant=True)
+KT = TypeVar('KT')
+VT_co = TypeVar('VT_co', covariant=True)
+
class CheckedType(object):
"""
@@ -271,7 +276,7 @@ def _checked_type_create(cls, source_data, _factory_fields=None, ignore_extra=Fa
return cls(source_data)
-class CheckedPVector(PythonPVector, CheckedType, metaclass=_CheckedTypeMeta):
+class CheckedPVector(Generic[T_co], PythonPVector, CheckedType, metaclass=_CheckedTypeMeta):
"""
A CheckedPVector is a PVector which allows specifying type and invariant checks.
@@ -357,7 +362,7 @@ class CheckedPVector(PythonPVector, CheckedType, metaclass=_CheckedTypeMeta):
return CheckedPVector.Evolver(self.__class__, self)
-class CheckedPSet(PSet, CheckedType, metaclass=_CheckedTypeMeta):
+class CheckedPSet(PSet[T_co], CheckedType, metaclass=_CheckedTypeMeta):
"""
A CheckedPSet is a PSet which allows specifying type and invariant checks.
@@ -455,7 +460,7 @@ class _CheckedMapTypeMeta(type):
_UNDEFINED_CHECKED_PMAP_SIZE = object()
-class CheckedPMap(PMap, CheckedType, metaclass=_CheckedMapTypeMeta):
+class CheckedPMap(PMap[KT, VT_co], CheckedType, metaclass=_CheckedMapTypeMeta):
"""
A CheckedPMap is a PMap which allows specifying type and invariant checks.
diff --git a/libs/pyrsistent/_helpers.py b/libs/pyrsistent/_helpers.py
index 1320e6576..b44bfc573 100644
--- a/libs/pyrsistent/_helpers.py
+++ b/libs/pyrsistent/_helpers.py
@@ -1,3 +1,4 @@
+import collections
from functools import wraps
from pyrsistent._pmap import PMap, pmap
from pyrsistent._pset import PSet, pset
@@ -10,6 +11,7 @@ def freeze(o, strict=True):
- list is converted to pvector, recursively
- dict is converted to pmap, recursively on values (but not keys)
+ - defaultdict is converted to pmap, recursively on values (but not keys)
- set is converted to pset, but not recursively
- tuple is converted to tuple, recursively.
@@ -33,6 +35,8 @@ def freeze(o, strict=True):
typ = type(o)
if typ is dict or (strict and isinstance(o, PMap)):
return pmap({k: freeze(v, strict) for k, v in o.items()})
+ if typ is collections.defaultdict or (strict and isinstance(o, PMap)):
+ 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))
diff --git a/libs/pyrsistent/_immutable.py b/libs/pyrsistent/_immutable.py
index 7c7594533..d23deca77 100644
--- a/libs/pyrsistent/_immutable.py
+++ b/libs/pyrsistent/_immutable.py
@@ -60,14 +60,9 @@ def immutable(members='', name='Immutable', verbose=False):
return ''
- verbose_string = ""
- if sys.version_info < (3, 7):
- # Verbose is no longer supported in Python 3.7
- verbose_string = ", verbose={verbose}".format(verbose=verbose)
-
quoted_members = ', '.join("'%s'" % m for m in members)
template = """
-class {class_name}(namedtuple('ImmutableBase', [{quoted_members}]{verbose_string})):
+class {class_name}(namedtuple('ImmutableBase', [{quoted_members}])):
__slots__ = tuple()
def __repr__(self):
@@ -87,7 +82,6 @@ class {class_name}(namedtuple('ImmutableBase', [{quoted_members}]{verbose_string
""".format(quoted_members=quoted_members,
member_set="set([%s])" % quoted_members if quoted_members else 'set()',
frozen_member_test=frozen_member_test(),
- verbose_string=verbose_string,
class_name=name)
if verbose:
diff --git a/libs/pyrsistent/_pbag.py b/libs/pyrsistent/_pbag.py
index 9cf5840b7..50001f191 100644
--- a/libs/pyrsistent/_pbag.py
+++ b/libs/pyrsistent/_pbag.py
@@ -1,13 +1,16 @@
from collections.abc import Container, Iterable, Sized, Hashable
from functools import reduce
+from typing import Generic, TypeVar
from pyrsistent._pmap import pmap
+T_co = TypeVar('T_co', covariant=True)
+
def _add_to_counters(counters, element):
return counters.set(element, counters.get(element, 0) + 1)
-class PBag(object):
+class PBag(Generic[T_co]):
"""
A persistent bag/multiset type.
diff --git a/libs/pyrsistent/_pdeque.py b/libs/pyrsistent/_pdeque.py
index bd11bfa03..0f25936af 100644
--- a/libs/pyrsistent/_pdeque.py
+++ b/libs/pyrsistent/_pdeque.py
@@ -1,10 +1,13 @@
from collections.abc import Sequence, Hashable
from itertools import islice, chain
from numbers import Integral
+from typing import TypeVar, Generic
from pyrsistent._plist import plist
+T_co = TypeVar('T_co', covariant=True)
-class PDeque(object):
+
+class PDeque(Generic[T_co]):
"""
Persistent double ended queue (deque). Allows quick appends and pops in both ends. Implemented
using two persistent lists.
@@ -175,7 +178,7 @@ class PDeque(object):
return False
def __hash__(self):
- return hash(tuple(self))
+ return hash(tuple(self))
def __len__(self):
return self._length
@@ -275,7 +278,7 @@ class PDeque(object):
try:
# This is severely inefficient with a double reverse, should perhaps implement a remove_last()?
return PDeque(self._left_list,
- self._right_list.reverse().remove(elem).reverse(), self._length - 1)
+ self._right_list.reverse().remove(elem).reverse(), self._length - 1)
except ValueError as e:
raise ValueError('{0} not found in PDeque'.format(elem)) from e
diff --git a/libs/pyrsistent/_plist.py b/libs/pyrsistent/_plist.py
index bea7f5ecf..322e15d64 100644
--- a/libs/pyrsistent/_plist.py
+++ b/libs/pyrsistent/_plist.py
@@ -1,6 +1,9 @@
from collections.abc import Sequence, Hashable
from numbers import Integral
from functools import reduce
+from typing import Generic, TypeVar
+
+T_co = TypeVar('T_co', covariant=True)
class _PListBuilder(object):
@@ -219,7 +222,7 @@ class _PListBase(object):
raise ValueError('{0} not found in PList'.format(elem))
-class PList(_PListBase):
+class PList(Generic[T_co], _PListBase):
"""
Classical Lisp style singly linked list. Adding elements to the head using cons is O(1).
Element access is O(k) where k is the position of the element in the list. Taking the
diff --git a/libs/pyrsistent/_pmap.py b/libs/pyrsistent/_pmap.py
index c6c7c7feb..0d82c4386 100644
--- a/libs/pyrsistent/_pmap.py
+++ b/libs/pyrsistent/_pmap.py
@@ -1,8 +1,12 @@
from collections.abc import Mapping, Hashable
from itertools import chain
+from typing import Generic, TypeVar
+
from pyrsistent._pvector import pvector
from pyrsistent._transformations import transform
+KT = TypeVar('KT')
+VT_co = TypeVar('VT_co', covariant=True)
class PMapView:
"""View type for the persistent map/dict type `PMap`.
@@ -103,7 +107,7 @@ class PMapItems(PMapView):
elif not isinstance(x, type(self)): return False
else: return self._map == x._map
-class PMap(object):
+class PMap(Generic[KT, VT_co]):
"""
Persistent map/dict. Tries to follow the same naming conventions as the built in dict where feasible.
@@ -409,7 +413,8 @@ class PMap(object):
for k, v in bucket:
if k == key:
if v is not val:
- new_bucket = [(k2, v2) if k2 != k else (k2, val) for k2, v2 in bucket]
+ # Use `not (k2 == k)` rather than `!=` to avoid relying on a well implemented `__ne__`, see #268.
+ new_bucket = [(k2, v2) if not (k2 == k) else (k2, val) for k2, v2 in bucket]
self._buckets_evolver[index] = new_bucket
return self
@@ -472,10 +477,12 @@ class PMap(object):
index, bucket = PMap._get_bucket(self._buckets_evolver, key)
if bucket:
- new_bucket = [(k, v) for (k, v) in bucket if k != key]
- if len(bucket) > len(new_bucket):
+ # Use `not (k == key)` rather than `!=` to avoid relying on a well implemented `__ne__`, see #268.
+ new_bucket = [(k, v) for (k, v) in bucket if not (k == key)]
+ size_diff = len(bucket) - len(new_bucket)
+ if size_diff > 0:
self._buckets_evolver[index] = new_bucket if new_bucket else None
- self._size -= 1
+ self._size -= size_diff
return self
raise KeyError('{0}'.format(key))
diff --git a/libs/pyrsistent/_pset.py b/libs/pyrsistent/_pset.py
index 4fae8278f..6247607db 100644
--- a/libs/pyrsistent/_pset.py
+++ b/libs/pyrsistent/_pset.py
@@ -1,9 +1,12 @@
from collections.abc import Set, Hashable
import sys
+from typing import TypeVar, Generic
from pyrsistent._pmap import pmap
+T_co = TypeVar('T_co', covariant=True)
-class PSet(object):
+
+class PSet(Generic[T_co]):
"""
Persistent set implementation. Built on top of the persistent map. The set supports all operations
in the Set protocol and is Hashable.
diff --git a/libs/pyrsistent/_pvector.py b/libs/pyrsistent/_pvector.py
index 2aff0e8b4..51d8a227b 100644
--- a/libs/pyrsistent/_pvector.py
+++ b/libs/pyrsistent/_pvector.py
@@ -2,8 +2,12 @@ from abc import abstractmethod, ABCMeta
from collections.abc import Sequence, Hashable
from numbers import Integral
import operator
+from typing import TypeVar, Generic
+
from pyrsistent._transformations import transform
+T_co = TypeVar('T_co', covariant=True)
+
def _bitcount(val):
return bin(val).count("1")
@@ -410,7 +414,7 @@ class PythonPVector(object):
l.remove(value)
return _EMPTY_PVECTOR.extend(l)
-class PVector(metaclass=ABCMeta):
+class PVector(Generic[T_co],metaclass=ABCMeta):
"""
Persistent vector implementation. Meant as a replacement for the cases where you would normally
use a Python list.
diff --git a/libs/pyrsistent/_transformations.py b/libs/pyrsistent/_transformations.py
index 7544843ac..6ef747f07 100644
--- a/libs/pyrsistent/_transformations.py
+++ b/libs/pyrsistent/_transformations.py
@@ -127,6 +127,10 @@ def _update_structure(structure, kvs, path, command):
for k, v in kvs:
is_empty = False
if v is _EMPTY_SENTINEL:
+ if command is discard:
+ # If nothing there when discarding just move on, do not introduce new nodes
+ continue
+
# Allow expansion of structure but make sure to cover the case
# when an empty pmap is added as leaf node. See #154.
is_empty = True
diff --git a/libs/pyrsistent/typing.py b/libs/pyrsistent/typing.py
index 6a86c831b..c97f9db52 100644
--- a/libs/pyrsistent/typing.py
+++ b/libs/pyrsistent/typing.py
@@ -36,36 +36,38 @@ try:
]
T = TypeVar('T')
+ T_co = TypeVar('T_co', covariant=True)
KT = TypeVar('KT')
VT = TypeVar('VT')
+ VT_co = TypeVar('VT_co', covariant=True)
- class CheckedPMap(Mapping[KT, VT], Hashable):
+ class CheckedPMap(Mapping[KT, VT_co], Hashable):
pass
# PSet.add and PSet.discard have different type signatures than that of Set.
- class CheckedPSet(Generic[T], Hashable):
+ class CheckedPSet(Generic[T_co], Hashable):
pass
- class CheckedPVector(Sequence[T], Hashable):
+ class CheckedPVector(Sequence[T_co], Hashable):
pass
- class PBag(Container[T], Iterable[T], Sized, Hashable):
+ class PBag(Container[T_co], Iterable[T_co], Sized, Hashable):
pass
- class PDeque(Sequence[T], Hashable):
+ class PDeque(Sequence[T_co], Hashable):
pass
- class PList(Sequence[T], Hashable):
+ class PList(Sequence[T_co], Hashable):
pass
- class PMap(Mapping[KT, VT], Hashable):
+ class PMap(Mapping[KT, VT_co], Hashable):
pass
# PSet.add and PSet.discard have different type signatures than that of Set.
- class PSet(Generic[T], Hashable):
+ class PSet(Generic[T_co], Hashable):
pass
- class PVector(Sequence[T], Hashable):
+ class PVector(Sequence[T_co], Hashable):
pass
class PVectorEvolver(Generic[T]):