pythonic-fp-gadgets 4.4.0__py3-none-any.whl → 4.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,6 @@ Gadgets
27
27
  """
28
28
 
29
29
  from collections.abc import Iterator
30
- from inspect import getmro
31
30
 
32
31
  __all__ = ['first_common_ancestor', 'iterate_over_arguments']
33
32
 
@@ -38,27 +37,33 @@ __license__ = 'Apache License 2.0'
38
37
 
39
38
  def first_common_ancestor(cls1: type, cls2: type) -> type:
40
39
  """
41
- .. admonition:: Least upper bound
40
+ .. admonition:: First common ancestor
42
41
 
43
- Find the least upper bound in the inheritance graph
44
- of two classes.
42
+ Best effort to find the least upper bound in the inheritance
43
+ graph of two classes.
45
44
 
46
45
  :param cls1: A class in the inheritance hierarchy.
47
46
  :param cls2: A class in the inheritance hierarchy.
48
- :returns: First common ancestor based on ``getmro`` order.
49
- :raises TypeError: Raised when no common ancestor exists, or when
50
- not caught when raised by ``inspect.getmro``.
47
+ :returns: First common ancestor in ``cls1.__mro__`` order.
48
+ :raises TypeError: Defensively raised when no common ancestor
49
+ is found.
51
50
 
52
- .. warning::
51
+ .. note::
52
+
53
+ The function is not symmetric in its arguments. In genuine
54
+ multiple inheritance graphs, swapping ``cls1`` and ``cls2``
55
+ can yield a different ancestor. Also, a virtual ancestor
56
+ registered with an ABC may be a tighter bound than anything
57
+ in the actual MRO.
53
58
 
54
- This function can fail with a TypeError. Some error messages
55
- seen are
59
+ .. note::
56
60
 
57
- - multiple bases have instance lay-out conflict
58
- - type 'bool' is not an acceptable base type
61
+ Since ``object`` terminates all actual MRO's, ``TypeError``
62
+ is unlikely to ever be thrown, except in the case of some
63
+ exotic metaclass breaking this assumption. This exception
64
+ is here mainly to let typing tools know that object ``None``
65
+ is not a possible return type.
59
66
 
60
- This happens frequently when the function is given
61
- Python builtin types or in multiple inheritance situations.
62
67
 
63
68
  """
64
69
  if issubclass(cls1, cls2):
@@ -66,10 +71,10 @@ def first_common_ancestor(cls1: type, cls2: type) -> type:
66
71
  if issubclass(cls2, cls1):
67
72
  return cls1
68
73
 
69
- for common_ancestor in getmro(type('LcaDiamondClass', (cls1, cls2), {})):
70
- if issubclass(cls1, common_ancestor) and issubclass(cls2, common_ancestor):
71
- return common_ancestor
72
- raise TypeError("latest_common_ancestor: no common ancestor found!!!")
74
+ for ancestor in cls1.__mro__:
75
+ if issubclass(cls2, ancestor):
76
+ return ancestor
77
+ raise TypeError("first_common_ancestor: no common ancestor found!")
73
78
 
74
79
 
75
80
  def iterate_over_arguments[A](*args: A) -> Iterator[A]:
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  from collections.abc import Callable, Iterator
16
- from typing import cast, Final, overload
16
+ from typing import Final, cast, overload
17
17
 
18
18
  __all__ = ['Box']
19
19
 
@@ -105,9 +105,7 @@ class Box[T]:
105
105
 
106
106
  if self._item is other._item:
107
107
  return True
108
- if self._item == other._item:
109
- return True
110
- return False
108
+ return self._item == other._item
111
109
 
112
110
  def __repr__(self) -> str:
113
111
  """
@@ -199,7 +197,6 @@ class Box[T]:
199
197
  else:
200
198
  msg = 'Box: Trying to push an item in a non-empty Box'
201
199
  raise ValueError(msg)
202
- return None
203
200
 
204
201
  def put(self, item: T) -> None:
205
202
  """
@@ -228,7 +225,7 @@ class Box[T]:
228
225
  self._item = new_item
229
226
  return popped
230
227
 
231
- def map[U](self, f: Callable[[T], U]) -> 'Box[U]':
228
+ def map[U](self, f: Callable[[T], U]) -> Box[U]:
232
229
  """
233
230
  .. admonition:: Map
234
231
 
@@ -243,7 +240,7 @@ class Box[T]:
243
240
  return Box()
244
241
  return Box(f(cast(T, self._item)))
245
242
 
246
- def bind[U](self, f: Callable[[T], 'Box[U]']) -> 'Box[U]':
243
+ def bind[U](self, f: Callable[[T], Box[U]]) -> Box[U]:
247
244
  """
248
245
  .. admonition:: Bind
249
246
 
@@ -147,7 +147,7 @@ class HWrap[T: Hashable](Hashable):
147
147
 
148
148
  .. tip::
149
149
 
150
- ``HWrap`` objects are hashable and matchable.
150
+ ``HWrap`` objects are matchable and hashable.
151
151
 
152
152
  """
153
153
 
@@ -163,7 +163,7 @@ class HWrap[T: Hashable](Hashable):
163
163
  :param item: Item to be wrapped.
164
164
 
165
165
  """
166
- self._item, self._hash = item, hash(item)
166
+ self._item, self._hash = item, hash((item, '_hwrap'))
167
167
 
168
168
  def __hash__(self) -> int:
169
169
  return self._hash
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pythonic-fp-gadgets
3
- Version: 4.4.0
3
+ Version: 4.6.0
4
4
  Summary: Gadgets without external Pythonic FP dependencies.
5
5
  Keywords: gadgets,no-external-dependencies
6
6
  Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
@@ -0,0 +1,11 @@
1
+ pythonic_fp/gadgets/__init__.py,sha256=XcjEjYz5Wi8VcSJ3BEqCWDyZ_6w_Q1m1XyUpFngBRUk,2973
2
+ pythonic_fp/gadgets/box.py,sha256=9BPmCp_pYjNr6si444p0C2n8Tfb1mtQn6IwAi_1oO54,7047
3
+ pythonic_fp/gadgets/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pythonic_fp/gadgets/wrap.py,sha256=QUN8ILCsqOqukDHBs9dZJmfwIkfp1E5jAQGLS9qwhi0,6462
5
+ pythonic_fp/gadgets/sentinels/__init__.py,sha256=Xh63-GTwiqqcBqs5OEYBSiLXuWtq_CVHfUz0mKO_2H0,775
6
+ pythonic_fp/gadgets/sentinels/flavored.py,sha256=LPmA-XOadcN5gJgxxo2prSnwRvq8bJ7o0Ae2_Y70Au0,2774
7
+ pythonic_fp/gadgets/sentinels/novalue.py,sha256=gaQNm1TRtphbmWgDV8O0sblH7eU2M-Zymu_B67mwsJ8,6097
8
+ pythonic_fp_gadgets-4.6.0.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
9
+ pythonic_fp_gadgets-4.6.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
10
+ pythonic_fp_gadgets-4.6.0.dist-info/METADATA,sha256=HlMLfKJ-FQ-PIcuMByqKp4o0fCXe_Jbzn-luUeludgE,1873
11
+ pythonic_fp_gadgets-4.6.0.dist-info/RECORD,,
File without changes
@@ -1,8 +0,0 @@
1
- from typing import Hashable
2
-
3
- __all__ = ['Sentinel']
4
-
5
- class Sentinel[H: Hashable]:
6
- def __new__(cls, flavor: H) -> Sentinel[H]: ...
7
- def __init__(self, flavor: H) -> None: ...
8
- def flavor(self) -> H: ...
@@ -1,8 +0,0 @@
1
- __all__ = ['NoValue']
2
-
3
- class NoValue:
4
- def __new__(cls) -> NoValue: ...
5
- def __hash__(self) -> int: ...
6
- def __bool__(self) -> bool: ...
7
- def __eq__(self, other: object) -> bool: ...
8
- def __ne__(self, other: object) -> bool: ...
@@ -1,14 +0,0 @@
1
- pythonic_fp/gadgets/__init__.py,sha256=zwRgxkaQYUbqjR-kX8pQeuPqipCB1bllVOEVBtGXl6I,2807
2
- pythonic_fp/gadgets/box.py,sha256=gcW9mg-QCjc2lLTcOeqYJK0NAkHAbFs1JxhFjVTW1uQ,7115
3
- pythonic_fp/gadgets/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- pythonic_fp/gadgets/wrap.py,sha256=qIIz2icfADzH8hbPRkaDc1SAB1xW-0aAvmZK6K6Drrs,6450
5
- pythonic_fp/gadgets/sentinels/__init__.py,sha256=Xh63-GTwiqqcBqs5OEYBSiLXuWtq_CVHfUz0mKO_2H0,775
6
- pythonic_fp/gadgets/sentinels/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- pythonic_fp/gadgets/sentinels/flavored.py,sha256=LPmA-XOadcN5gJgxxo2prSnwRvq8bJ7o0Ae2_Y70Au0,2774
8
- pythonic_fp/gadgets/sentinels/flavored.pyi,sha256=K3YSyXLyylPII2ahRP0olhzLJruOeR73TFJDC6rCUwk,212
9
- pythonic_fp/gadgets/sentinels/novalue.py,sha256=gaQNm1TRtphbmWgDV8O0sblH7eU2M-Zymu_B67mwsJ8,6097
10
- pythonic_fp/gadgets/sentinels/novalue.pyi,sha256=1_iUI6FEwYma8P4XXVCb6CKhSYmfq53S8dLmiwNtJw4,244
11
- pythonic_fp_gadgets-4.4.0.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
12
- pythonic_fp_gadgets-4.4.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
13
- pythonic_fp_gadgets-4.4.0.dist-info/METADATA,sha256=ENqFG1uY3opG16K6Ov6owe-yjnyY3Z8UCZnZCWOmluo,1873
14
- pythonic_fp_gadgets-4.4.0.dist-info/RECORD,,