omlish 0.0.0.dev1__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.

Potentially problematic release.


This version of omlish might be problematic. Click here for more details.

Files changed (187) hide show
  1. omlish/__about__.py +7 -0
  2. omlish/__init__.py +0 -0
  3. omlish/argparse.py +223 -0
  4. omlish/asyncs/__init__.py +17 -0
  5. omlish/asyncs/anyio.py +23 -0
  6. omlish/asyncs/asyncio.py +19 -0
  7. omlish/asyncs/asyncs.py +76 -0
  8. omlish/asyncs/futures.py +179 -0
  9. omlish/asyncs/trio.py +11 -0
  10. omlish/c3.py +173 -0
  11. omlish/cached.py +9 -0
  12. omlish/check.py +231 -0
  13. omlish/collections/__init__.py +63 -0
  14. omlish/collections/_abc.py +156 -0
  15. omlish/collections/_io_abc.py +78 -0
  16. omlish/collections/cache/__init__.py +11 -0
  17. omlish/collections/cache/descriptor.py +188 -0
  18. omlish/collections/cache/impl.py +485 -0
  19. omlish/collections/cache/types.py +37 -0
  20. omlish/collections/coerce.py +337 -0
  21. omlish/collections/frozen.py +148 -0
  22. omlish/collections/identity.py +106 -0
  23. omlish/collections/indexed.py +75 -0
  24. omlish/collections/mappings.py +127 -0
  25. omlish/collections/ordered.py +81 -0
  26. omlish/collections/persistent.py +36 -0
  27. omlish/collections/skiplist.py +193 -0
  28. omlish/collections/sorted.py +126 -0
  29. omlish/collections/treap.py +228 -0
  30. omlish/collections/treapmap.py +144 -0
  31. omlish/collections/unmodifiable.py +174 -0
  32. omlish/collections/utils.py +110 -0
  33. omlish/configs/__init__.py +0 -0
  34. omlish/configs/flattening.py +147 -0
  35. omlish/configs/props.py +64 -0
  36. omlish/dataclasses/__init__.py +83 -0
  37. omlish/dataclasses/impl/__init__.py +6 -0
  38. omlish/dataclasses/impl/api.py +260 -0
  39. omlish/dataclasses/impl/as_.py +76 -0
  40. omlish/dataclasses/impl/exceptions.py +2 -0
  41. omlish/dataclasses/impl/fields.py +148 -0
  42. omlish/dataclasses/impl/frozen.py +55 -0
  43. omlish/dataclasses/impl/hashing.py +85 -0
  44. omlish/dataclasses/impl/init.py +173 -0
  45. omlish/dataclasses/impl/internals.py +118 -0
  46. omlish/dataclasses/impl/main.py +150 -0
  47. omlish/dataclasses/impl/metaclass.py +126 -0
  48. omlish/dataclasses/impl/metadata.py +74 -0
  49. omlish/dataclasses/impl/order.py +47 -0
  50. omlish/dataclasses/impl/params.py +150 -0
  51. omlish/dataclasses/impl/processing.py +16 -0
  52. omlish/dataclasses/impl/reflect.py +173 -0
  53. omlish/dataclasses/impl/replace.py +40 -0
  54. omlish/dataclasses/impl/repr.py +34 -0
  55. omlish/dataclasses/impl/simple.py +92 -0
  56. omlish/dataclasses/impl/slots.py +80 -0
  57. omlish/dataclasses/impl/utils.py +167 -0
  58. omlish/defs.py +193 -0
  59. omlish/dispatch/__init__.py +3 -0
  60. omlish/dispatch/dispatch.py +137 -0
  61. omlish/dispatch/functions.py +52 -0
  62. omlish/dispatch/methods.py +162 -0
  63. omlish/docker.py +149 -0
  64. omlish/dynamic.py +220 -0
  65. omlish/graphs/__init__.py +0 -0
  66. omlish/graphs/dot/__init__.py +19 -0
  67. omlish/graphs/dot/items.py +162 -0
  68. omlish/graphs/dot/rendering.py +147 -0
  69. omlish/graphs/dot/utils.py +30 -0
  70. omlish/graphs/trees.py +249 -0
  71. omlish/http/__init__.py +0 -0
  72. omlish/http/consts.py +20 -0
  73. omlish/http/wsgi.py +34 -0
  74. omlish/inject/__init__.py +85 -0
  75. omlish/inject/binder.py +12 -0
  76. omlish/inject/bindings.py +49 -0
  77. omlish/inject/eagers.py +21 -0
  78. omlish/inject/elements.py +43 -0
  79. omlish/inject/exceptions.py +49 -0
  80. omlish/inject/impl/__init__.py +0 -0
  81. omlish/inject/impl/bindings.py +19 -0
  82. omlish/inject/impl/elements.py +154 -0
  83. omlish/inject/impl/injector.py +182 -0
  84. omlish/inject/impl/inspect.py +98 -0
  85. omlish/inject/impl/private.py +109 -0
  86. omlish/inject/impl/providers.py +132 -0
  87. omlish/inject/impl/scopes.py +198 -0
  88. omlish/inject/injector.py +40 -0
  89. omlish/inject/inspect.py +14 -0
  90. omlish/inject/keys.py +43 -0
  91. omlish/inject/managed.py +24 -0
  92. omlish/inject/overrides.py +18 -0
  93. omlish/inject/private.py +29 -0
  94. omlish/inject/providers.py +111 -0
  95. omlish/inject/proxy.py +48 -0
  96. omlish/inject/scopes.py +84 -0
  97. omlish/inject/types.py +21 -0
  98. omlish/iterators.py +184 -0
  99. omlish/json.py +194 -0
  100. omlish/lang/__init__.py +112 -0
  101. omlish/lang/cached.py +267 -0
  102. omlish/lang/classes/__init__.py +24 -0
  103. omlish/lang/classes/abstract.py +74 -0
  104. omlish/lang/classes/restrict.py +137 -0
  105. omlish/lang/classes/simple.py +120 -0
  106. omlish/lang/classes/test/__init__.py +0 -0
  107. omlish/lang/classes/test/test_abstract.py +89 -0
  108. omlish/lang/classes/test/test_restrict.py +71 -0
  109. omlish/lang/classes/test/test_simple.py +58 -0
  110. omlish/lang/classes/test/test_virtual.py +72 -0
  111. omlish/lang/classes/virtual.py +130 -0
  112. omlish/lang/clsdct.py +67 -0
  113. omlish/lang/cmp.py +63 -0
  114. omlish/lang/contextmanagers.py +249 -0
  115. omlish/lang/datetimes.py +67 -0
  116. omlish/lang/descriptors.py +52 -0
  117. omlish/lang/functions.py +126 -0
  118. omlish/lang/imports.py +153 -0
  119. omlish/lang/iterables.py +54 -0
  120. omlish/lang/maybes.py +136 -0
  121. omlish/lang/objects.py +103 -0
  122. omlish/lang/resolving.py +50 -0
  123. omlish/lang/strings.py +128 -0
  124. omlish/lang/typing.py +92 -0
  125. omlish/libc.py +532 -0
  126. omlish/logs/__init__.py +9 -0
  127. omlish/logs/_abc.py +247 -0
  128. omlish/logs/configs.py +62 -0
  129. omlish/logs/filters.py +9 -0
  130. omlish/logs/formatters.py +67 -0
  131. omlish/logs/utils.py +20 -0
  132. omlish/marshal/__init__.py +52 -0
  133. omlish/marshal/any.py +25 -0
  134. omlish/marshal/base.py +201 -0
  135. omlish/marshal/base64.py +25 -0
  136. omlish/marshal/dataclasses.py +115 -0
  137. omlish/marshal/datetimes.py +90 -0
  138. omlish/marshal/enums.py +43 -0
  139. omlish/marshal/exceptions.py +7 -0
  140. omlish/marshal/factories.py +129 -0
  141. omlish/marshal/global_.py +33 -0
  142. omlish/marshal/iterables.py +57 -0
  143. omlish/marshal/mappings.py +66 -0
  144. omlish/marshal/naming.py +17 -0
  145. omlish/marshal/objects.py +106 -0
  146. omlish/marshal/optionals.py +49 -0
  147. omlish/marshal/polymorphism.py +147 -0
  148. omlish/marshal/primitives.py +43 -0
  149. omlish/marshal/registries.py +57 -0
  150. omlish/marshal/standard.py +80 -0
  151. omlish/marshal/utils.py +23 -0
  152. omlish/marshal/uuids.py +29 -0
  153. omlish/marshal/values.py +30 -0
  154. omlish/math.py +184 -0
  155. omlish/os.py +32 -0
  156. omlish/reflect.py +359 -0
  157. omlish/replserver/__init__.py +5 -0
  158. omlish/replserver/__main__.py +4 -0
  159. omlish/replserver/console.py +247 -0
  160. omlish/replserver/server.py +146 -0
  161. omlish/runmodule.py +28 -0
  162. omlish/stats.py +342 -0
  163. omlish/term.py +222 -0
  164. omlish/testing/__init__.py +7 -0
  165. omlish/testing/pydevd.py +225 -0
  166. omlish/testing/pytest/__init__.py +8 -0
  167. omlish/testing/pytest/helpers.py +35 -0
  168. omlish/testing/pytest/inject/__init__.py +1 -0
  169. omlish/testing/pytest/inject/harness.py +159 -0
  170. omlish/testing/pytest/plugins/__init__.py +20 -0
  171. omlish/testing/pytest/plugins/_registry.py +6 -0
  172. omlish/testing/pytest/plugins/logging.py +13 -0
  173. omlish/testing/pytest/plugins/pycharm.py +54 -0
  174. omlish/testing/pytest/plugins/repeat.py +19 -0
  175. omlish/testing/pytest/plugins/skips.py +32 -0
  176. omlish/testing/pytest/plugins/spacing.py +19 -0
  177. omlish/testing/pytest/plugins/switches.py +70 -0
  178. omlish/testing/testing.py +102 -0
  179. omlish/text/__init__.py +0 -0
  180. omlish/text/delimit.py +171 -0
  181. omlish/text/indent.py +50 -0
  182. omlish/text/parts.py +265 -0
  183. omlish-0.0.0.dev1.dist-info/LICENSE +21 -0
  184. omlish-0.0.0.dev1.dist-info/METADATA +17 -0
  185. omlish-0.0.0.dev1.dist-info/RECORD +187 -0
  186. omlish-0.0.0.dev1.dist-info/WHEEL +5 -0
  187. omlish-0.0.0.dev1.dist-info/top_level.txt +1 -0
omlish/c3.py ADDED
@@ -0,0 +1,173 @@
1
+ """
2
+ PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
3
+ --------------------------------------------
4
+
5
+ 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization
6
+ ("Licensee") accessing and otherwise using this software ("Python") in source or binary form and its associated
7
+ documentation.
8
+
9
+ 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive,
10
+ royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works,
11
+ distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement
12
+ and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
13
+ 2012, 2013, 2014, 2015, 2016, 2017 Python Software Foundation; All Rights Reserved" are retained in Python alone or in
14
+ any derivative version prepared by Licensee.
15
+
16
+ 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and
17
+ wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any
18
+ such work a brief summary of the changes made to Python.
19
+
20
+ 4. PSF is making Python available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS
21
+ OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF
22
+ MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT INFRINGE ANY THIRD PARTY
23
+ RIGHTS.
24
+
25
+ 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL
26
+ DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR ANY DERIVATIVE THEREOF, EVEN IF
27
+ ADVISED OF THE POSSIBILITY THEREOF.
28
+
29
+ 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions.
30
+
31
+ 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture
32
+ between PSF and Licensee. This License Agreement does not grant permission to use PSF trademarks or trade name in a
33
+ trademark sense to endorse or promote products or services of Licensee, or any third party.
34
+
35
+ 8. By copying, installing or otherwise using Python, Licensee agrees to be bound by the terms and conditions of this
36
+ License Agreement.
37
+ """
38
+ import operator
39
+ import typing as ta
40
+
41
+
42
+ T = ta.TypeVar('T')
43
+
44
+
45
+ def merge(seqs: ta.MutableSequence[list[T]]) -> list[T]:
46
+ """Merges MROs in *sequences* to a single MRO using the C3 algorithm.
47
+
48
+ Adapted from https://www.python.org/download/releases/2.3/mro/.
49
+ """
50
+
51
+ result: list[T] = []
52
+ candidate: ta.Optional[T] = None
53
+ while True:
54
+ seqs = [s for s in seqs if s] # purge empty sequences
55
+ if not seqs:
56
+ return result
57
+ for s1 in seqs: # find merge candidates among seq heads
58
+ candidate = s1[0]
59
+ for s2 in seqs:
60
+ if candidate in s2[1:]:
61
+ candidate = None
62
+ break # reject the current head, it appears later
63
+ else:
64
+ break
65
+ if candidate is None:
66
+ raise RuntimeError('Inconsistent hierarchy')
67
+ result.append(candidate)
68
+ # remove the chosen candidate
69
+ for seq in seqs:
70
+ if seq[0] == candidate:
71
+ del seq[0]
72
+
73
+
74
+ def mro(
75
+ cls: T,
76
+ abcs: ta.Optional[ta.Sequence[T]] = None,
77
+ *,
78
+ get_bases: ta.Callable[[T], ta.Sequence[T]] = operator.attrgetter('__bases__'),
79
+ is_subclass: ta.Callable[[T, T], bool] = issubclass, # type: ignore
80
+ ) -> list[T]:
81
+ """Computes the method resolution order using extended C3 linearization.
82
+
83
+ If no *abcs* are given, the algorithm works exactly like the built-in C3 linearization used for method resolution.
84
+
85
+ If given, *abcs* is a list of abstract base classes that should be inserted into the resulting MRO. Unrelated ABCs
86
+ are ignored and don't end up in the result. The algorithm inserts ABCs where their functionality is introduced, i.e.
87
+ issubclass(cls, abc) returns True for the class itself but returns False for all its direct base classes. Implicit
88
+ ABCs for a given class (either registered or inferred from the presence of a special method like __len__) are
89
+ inserted directly after the last ABC explicitly listed in the MRO of said class. If two implicit ABCs end up next to
90
+ each other in the resulting MRO, their ordering depends on the order of types in *abcs*.
91
+ """
92
+
93
+ for i, base in enumerate(reversed(get_bases(cls))):
94
+ if hasattr(base, '__abstractmethods__'):
95
+ boundary = len(get_bases(cls)) - i
96
+ break # Bases up to the last explicit ABC are considered first.
97
+ else:
98
+ boundary = 0
99
+ abcs = list(abcs) if abcs else []
100
+ explicit_bases = list(get_bases(cls)[:boundary])
101
+ abstract_bases = []
102
+ other_bases = list(get_bases(cls)[boundary:])
103
+ for base in abcs:
104
+ if (
105
+ is_subclass(cls, base) and # noqa
106
+ not any(is_subclass(b, base) for b in get_bases(cls)) # noqa
107
+ ):
108
+ # If *cls* is the class that introduces behaviour described by an ABC *base*, insert said ABC to its MRO.
109
+ abstract_bases.append(base)
110
+ for base in abstract_bases:
111
+ abcs.remove(base)
112
+ explicit_c3_mros = [mro(base, abcs=abcs, get_bases=get_bases, is_subclass=is_subclass) for base in explicit_bases]
113
+ abstract_c3_mros = [mro(base, abcs=abcs, get_bases=get_bases, is_subclass=is_subclass) for base in abstract_bases]
114
+ other_c3_mros = [mro(base, abcs=abcs, get_bases=get_bases, is_subclass=is_subclass) for base in other_bases]
115
+ return merge(
116
+ [[cls]] +
117
+ explicit_c3_mros + abstract_c3_mros + other_c3_mros +
118
+ [explicit_bases] + [abstract_bases] + [other_bases]
119
+ )
120
+
121
+
122
+ def compose_mro(
123
+ cls: T,
124
+ types: ta.Iterable[T],
125
+ *,
126
+ get_mro: ta.Callable[[T], ta.Optional[ta.Sequence[T]]] = operator.attrgetter('__mro__'),
127
+ get_bases: ta.Callable[[T], ta.Sequence[T]] = operator.attrgetter('__bases__'),
128
+ is_subclass: ta.Callable[[T, T], bool] = issubclass, # type: ignore
129
+ get_subclasses: ta.Callable[[T], ta.Iterable[T]] = operator.methodcaller('__subclasses__'),
130
+ ) -> list[T]:
131
+ """Calculates the method resolution order for a given class *cls*.
132
+
133
+ Includes relevant abstract base classes (with their respective bases) from the *types* list. Uses a modified C3
134
+ linearization algorithm.
135
+ """
136
+
137
+ bases = set(get_mro(cls) or [])
138
+
139
+ # Remove entries which are already present in the __mro__ or unrelated.
140
+ def is_related(typ):
141
+ return typ not in bases and get_mro(typ) is not None and is_subclass(cls, typ)
142
+
143
+ types = [n for n in types if is_related(n)]
144
+
145
+ # Remove entries which are strict bases of other entries (they will end up in the MRO anyway.
146
+ def is_strict_base(typ):
147
+ for other in types:
148
+ if typ != other and typ in (get_mro(other) or []):
149
+ return True
150
+ return False
151
+
152
+ types = [n for n in types if not is_strict_base(n)]
153
+
154
+ # Subclasses of the ABCs in *types* which are also implemented by *cls* can be used to stabilize ABC ordering.
155
+ type_set = set(types)
156
+ _mro = []
157
+ for typ in types:
158
+ found: list[list[T]] = []
159
+ for sub in get_subclasses(typ):
160
+ if sub not in bases and is_subclass(cls, sub): # noqa
161
+ found.append([s for s in (get_mro(sub) or []) if s in type_set])
162
+ if not found:
163
+ _mro.append(typ)
164
+ continue
165
+
166
+ # Favor subclasses with the biggest number of useful bases
167
+ found.sort(key=len, reverse=True)
168
+ for lst in found:
169
+ for subcls in lst:
170
+ if subcls not in _mro:
171
+ _mro.append(subcls)
172
+
173
+ return mro(cls, abcs=_mro, get_bases=get_bases, is_subclass=is_subclass)
omlish/cached.py ADDED
@@ -0,0 +1,9 @@
1
+ from .lang.cached import cached_function
2
+ from .lang.cached import _CachedProperty # noqa
3
+
4
+
5
+ function = cached_function
6
+
7
+ property = property # noqa
8
+
9
+ globals()['property'] = _CachedProperty # noqa
omlish/check.py ADDED
@@ -0,0 +1,231 @@
1
+ """
2
+ TODO:
3
+ - def maybe(v: lang.Maybe[T])
4
+ """
5
+ import collections
6
+ import typing as ta
7
+
8
+
9
+ T = ta.TypeVar('T')
10
+ SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
11
+
12
+ Message = ta.Union[str, ta.Callable[..., ta.Optional[str]], None]
13
+
14
+ _NONE_TYPE = type(None)
15
+
16
+ _isinstance = isinstance
17
+ _issubclass = issubclass
18
+ _callable = callable
19
+
20
+
21
+ ##
22
+
23
+
24
+ def _default_exception_factory(exc_cls: type[Exception], *args, **kwargs) -> Exception:
25
+ return exc_cls(*args, **kwargs) # noqa
26
+
27
+
28
+ _EXCEPTION_FACTORY = _default_exception_factory
29
+
30
+
31
+ def _raise(
32
+ exception_type: type[Exception],
33
+ default_message: str,
34
+ message: Message,
35
+ *args: ta.Any,
36
+ **kwargs: ta.Any
37
+ ) -> ta.NoReturn:
38
+ if _callable(message):
39
+ message = ta.cast(ta.Callable, message)(*args, **kwargs)
40
+ if _isinstance(message, tuple):
41
+ message, *args = message # type: ignore
42
+ if message is None:
43
+ message = default_message
44
+ exc = _EXCEPTION_FACTORY(exception_type, message, *args, **kwargs)
45
+ raise exc
46
+
47
+
48
+ ##
49
+
50
+
51
+ def _unpack_isinstance_spec(spec: ta.Any) -> tuple:
52
+ if not _isinstance(spec, tuple):
53
+ spec = (spec,)
54
+ if None in spec:
55
+ spec = tuple(filter(None, spec)) + (_NONE_TYPE,)
56
+ if ta.Any in spec:
57
+ spec = (object,)
58
+ return spec
59
+
60
+
61
+ def isinstance(v: ta.Any, spec: ta.Union[type[T], tuple], msg: Message = None) -> T: # noqa
62
+ if not _isinstance(v, _unpack_isinstance_spec(spec)):
63
+ _raise(TypeError, 'Must be instance', msg, v, spec)
64
+ return v
65
+
66
+
67
+ def of_isinstance(spec: ta.Union[type[T], tuple], msg: Message = None) -> ta.Callable[[ta.Any], T]:
68
+ def inner(v):
69
+ return isinstance(v, _unpack_isinstance_spec(spec), msg)
70
+
71
+ return inner
72
+
73
+
74
+ def cast(v: ta.Any, cls: type[T], msg: Message = None) -> T: # noqa
75
+ if not _isinstance(v, cls):
76
+ _raise(TypeError, 'Must be instance', msg, v, cls)
77
+ return v
78
+
79
+
80
+ def of_cast(cls: type[T], msg: Message = None) -> ta.Callable[[T], T]:
81
+ def inner(v):
82
+ return isinstance(v, cls, msg)
83
+
84
+ return inner
85
+
86
+
87
+ def not_isinstance(v: T, spec: ta.Any, msg: Message = None) -> T: # noqa
88
+ if _isinstance(v, _unpack_isinstance_spec(spec)):
89
+ _raise(TypeError, 'Must not be instance', msg, v, spec)
90
+ return v
91
+
92
+
93
+ def of_not_isinstance(spec: ta.Any, msg: Message = None) -> ta.Callable[[T], T]:
94
+ def inner(v):
95
+ return not_isinstance(v, _unpack_isinstance_spec(spec), msg)
96
+
97
+ return inner
98
+
99
+
100
+ ##
101
+
102
+
103
+ def issubclass(v: type[T], spec: ta.Any, msg: Message = None) -> type[T]: # noqa
104
+ if not _issubclass(v, spec):
105
+ _raise(TypeError, 'Must be subclass', msg, v, spec)
106
+ return v
107
+
108
+
109
+ def not_issubclass(v: type[T], spec: ta.Any, msg: Message = None) -> type[T]: # noqa
110
+ if _issubclass(v, spec):
111
+ _raise(TypeError, 'Must not be subclass', msg, v, spec)
112
+ return v
113
+
114
+
115
+ ##
116
+
117
+
118
+ def in_(v: T, c: ta.Container[T], msg: Message = None) -> T:
119
+ if v not in c:
120
+ _raise(ValueError, 'Must be in', msg, v, c)
121
+ return v
122
+
123
+
124
+ def not_in(v: T, c: ta.Container[T], msg: Message = None) -> T:
125
+ if v in c:
126
+ _raise(ValueError, 'Must not be in', msg, v, c)
127
+ return v
128
+
129
+
130
+ def empty(v: SizedT, msg: Message = None) -> SizedT:
131
+ if len(v) != 0:
132
+ _raise(ValueError, 'Must be empty', msg, v)
133
+ return v
134
+
135
+
136
+ def not_empty(v: SizedT, msg: Message = None) -> SizedT:
137
+ if len(v) == 0:
138
+ _raise(ValueError, 'Must not be empty', msg, v)
139
+ return v
140
+
141
+
142
+ def unique(it: ta.Iterable[T], msg: Message = None) -> ta.Iterable[T]:
143
+ dupes = [e for e, c in collections.Counter(it).items() if c > 1]
144
+ if dupes:
145
+ _raise(ValueError, 'Must be unique', msg, it, dupes)
146
+ return it
147
+
148
+
149
+ def single(obj: ta.Iterable[T], message: Message = None) -> T:
150
+ try:
151
+ [value] = obj
152
+ except ValueError:
153
+ _raise(ValueError, 'Must be single', message, obj)
154
+ else:
155
+ return value
156
+
157
+
158
+ def optional_single(obj: ta.Iterable[T], message: Message = None) -> ta.Optional[T]:
159
+ it = iter(obj)
160
+ try:
161
+ value = next(it)
162
+ except StopIteration:
163
+ return None
164
+ try:
165
+ next(it)
166
+ except StopIteration:
167
+ return value # noqa
168
+ _raise(ValueError, 'Must be empty or single', message, obj)
169
+
170
+
171
+ ##
172
+
173
+
174
+ def none(v: ta.Any, msg: Message = None) -> None:
175
+ if v is not None:
176
+ _raise(ValueError, 'Must be None', msg, v)
177
+
178
+
179
+ def not_none(v: ta.Optional[T], msg: Message = None) -> T:
180
+ if v is None:
181
+ _raise(ValueError, 'Must not be None', msg, v)
182
+ return v
183
+
184
+
185
+ ##
186
+
187
+
188
+ def equal(v: T, *os: ta.Any, msg: Message = None) -> T:
189
+ for o in os:
190
+ if o != v:
191
+ _raise(ValueError, 'Must be equal', msg, v, os)
192
+ return v
193
+
194
+
195
+ def is_(v: T, *os: ta.Any, msg: Message = None) -> T:
196
+ for o in os:
197
+ if o is not v:
198
+ _raise(ValueError, 'Must be the same', msg, v, os)
199
+ return v
200
+
201
+
202
+ def is_not(v: T, *os: ta.Any, msg: Message = None) -> T:
203
+ for o in os:
204
+ if o is v:
205
+ _raise(ValueError, 'Must not be the same', msg, v, os)
206
+ return v
207
+
208
+
209
+ def callable(v: T, msg: Message = None) -> T:
210
+ if not _callable(v):
211
+ _raise(TypeError, 'Must be callable', msg, v)
212
+ return v # type: ignore
213
+
214
+
215
+ def non_empty_str(v: ta.Optional[str], msg: Message = None) -> str:
216
+ if not _isinstance(v, str) or not v:
217
+ _raise(ValueError, 'Must be non-empty str', msg, v)
218
+ return v
219
+
220
+
221
+ ##
222
+
223
+
224
+ def arg(v: bool, msg: Message = None) -> None:
225
+ if not v:
226
+ _raise(RuntimeError, 'Argument condition not met', msg)
227
+
228
+
229
+ def state(v: bool, msg: Message = None) -> None:
230
+ if not v:
231
+ _raise(RuntimeError, 'State condition not met', msg)
@@ -0,0 +1,63 @@
1
+ from .coerce import abs_set # noqa
2
+ from .coerce import abs_set_of # noqa
3
+ from .coerce import abs_set_of_or_none # noqa
4
+ from .coerce import abs_set_or_none # noqa
5
+ from .coerce import frozenset_ # noqa
6
+ from .coerce import frozenset_of # noqa
7
+ from .coerce import frozenset_of_or_none # noqa
8
+ from .coerce import frozenset_or_none # noqa
9
+ from .coerce import map # noqa
10
+ from .coerce import map_of # noqa
11
+ from .coerce import map_of_or_none # noqa
12
+ from .coerce import map_or_none # noqa
13
+ from .coerce import opt_abs_set # noqa
14
+ from .coerce import opt_abs_set_of # noqa
15
+ from .coerce import opt_frozenset # noqa
16
+ from .coerce import opt_frozenset_of # noqa
17
+ from .coerce import opt_map # noqa
18
+ from .coerce import opt_map_of # noqa
19
+ from .coerce import opt_seq # noqa
20
+ from .coerce import opt_seq_of # noqa
21
+ from .coerce import seq # noqa
22
+ from .coerce import seq_of # noqa
23
+ from .coerce import seq_of_or_none # noqa
24
+ from .coerce import seq_or_none # noqa
25
+ from .frozen import Frozen # noqa
26
+ from .frozen import FrozenDict # noqa
27
+ from .frozen import FrozenList # noqa
28
+ from .frozen import frozendict # noqa
29
+ from .frozen import frozenlist # noqa
30
+ from .identity import IdentityKeyDict # noqa
31
+ from .identity import IdentitySet # noqa
32
+ from .identity import IdentityWrapper # noqa
33
+ from .indexed import IndexedSeq # noqa
34
+ from .indexed import IndexedSetSeq # noqa
35
+ from .mappings import MissingDict # noqa
36
+ from .mappings import TypeMap # noqa
37
+ from .mappings import TypeMultiMap # noqa
38
+ from .mappings import guarded_map_update # noqa
39
+ from .mappings import multikey_dict # noqa
40
+ from .mappings import yield_dict_init # noqa
41
+ from .ordered import OrderedFrozenSet # noqa
42
+ from .ordered import OrderedSet # noqa
43
+ from .persistent import PersistentMap # noqa
44
+ from .skiplist import SkipList # noqa
45
+ from .skiplist import SkipListDict # noqa
46
+ from .sorted import SortedCollection # noqa
47
+ from .sorted import SortedListDict # noqa
48
+ from .sorted import SortedMapping # noqa
49
+ from .sorted import SortedMutableMapping # noqa
50
+ from .treapmap import new_treap_map # noqa
51
+ from .unmodifiable import Unmodifiable # noqa
52
+ from .unmodifiable import UnmodifiableMapping # noqa
53
+ from .unmodifiable import UnmodifiableSequence # noqa
54
+ from .unmodifiable import UnmodifiableSet # noqa
55
+ from .utils import all_equal # noqa
56
+ from .utils import all_not_equal # noqa
57
+ from .utils import indexes # noqa
58
+ from .utils import key_cmp # noqa
59
+ from .utils import mut_toposort # noqa
60
+ from .utils import partition # noqa
61
+ from .utils import toposort # noqa
62
+ from .utils import unique # noqa
63
+ from .utils import unique_dict # noqa
@@ -0,0 +1,156 @@
1
+ class Hashable:
2
+ def __hash__(self): ...
3
+
4
+
5
+ class Iterable:
6
+ def __iter__(self): ...
7
+
8
+
9
+ class Iterator(Iterable):
10
+ def __next__(self): ...
11
+
12
+
13
+ class Reversible(Iterable):
14
+ def __reversed__(self): ...
15
+
16
+
17
+ class Sized:
18
+ def __len__(self): ...
19
+
20
+
21
+ class Container:
22
+ def __contains__(self, x): ...
23
+
24
+
25
+ class Collection(Sized, Iterable, Container):
26
+ pass
27
+
28
+
29
+ # region Sequence
30
+
31
+
32
+ class Sequence(Reversible, Collection):
33
+ def __getitem__(self, index): ...
34
+
35
+ def index(self, value, start=0, stop=None): ...
36
+
37
+ def count(self, value): ...
38
+
39
+
40
+ class MutableSequence(Sequence):
41
+ def __setitem__(self, index, value): ...
42
+
43
+ def __delitem__(self, index): ...
44
+
45
+ def insert(self, index, value): ...
46
+
47
+ def append(self, value): ...
48
+
49
+ def clear(self): ...
50
+
51
+ def reverse(self): ...
52
+
53
+ def extend(self, values): ...
54
+
55
+ def pop(self, index=-1): ...
56
+
57
+ def remove(self, value): ...
58
+
59
+ def __iadd__(self, values): ...
60
+
61
+
62
+ # endregion
63
+
64
+
65
+ # region Set
66
+
67
+
68
+ class Set(Collection):
69
+ def __le__(self, other): ...
70
+
71
+ def __lt__(self, other): ...
72
+
73
+ def __gt__(self, other): ...
74
+
75
+ def __ge__(self, other): ...
76
+
77
+ def __eq__(self, other): ...
78
+
79
+ def __and__(self, other): ...
80
+
81
+ __rand__ = __and__
82
+
83
+ def isdisjoint(self, other): ...
84
+
85
+ def __or__(self, other): ...
86
+
87
+ __ror__ = __or__
88
+
89
+ def __sub__(self, other): ...
90
+
91
+ def __rsub__(self, other): ...
92
+
93
+ def __xor__(self, other): ...
94
+
95
+ __rxor__ = __xor__
96
+
97
+
98
+ class MutableSet(Set):
99
+ def add(self, value): ...
100
+
101
+ def discard(self, value): ...
102
+
103
+ def remove(self, value): ...
104
+
105
+ def pop(self): ...
106
+
107
+ def clear(self): ...
108
+
109
+ def __ior__(self, it): ...
110
+
111
+ def __iand__(self, it): ...
112
+
113
+ def __ixor__(self, it): ...
114
+
115
+ def __isub__(self, it): ...
116
+
117
+
118
+ # endregion
119
+
120
+
121
+ # region Mapping
122
+
123
+
124
+ class Mapping(Collection):
125
+ def __getitem__(self, key): ...
126
+
127
+ def get(self, key, default=None): ...
128
+
129
+ def keys(self): ...
130
+
131
+ def items(self): ...
132
+
133
+ def values(self): ...
134
+
135
+ def __eq__(self, other): ...
136
+
137
+ __reversed__ = None
138
+
139
+
140
+ class MutableMapping(Mapping):
141
+ def __setitem__(self, key, value): ...
142
+
143
+ def __delitem__(self, key): ...
144
+
145
+ def pop(self, key, default=None): ...
146
+
147
+ def popitem(self): ...
148
+
149
+ def clear(self): ...
150
+
151
+ def update(self, other=(), **kwds): ...
152
+
153
+ def setdefault(self, key, default=None): ...
154
+
155
+
156
+ # endregion
@@ -0,0 +1,78 @@
1
+ class IOBase:
2
+ def seek(self, pos, whence=0): ...
3
+
4
+ def tell(self): ...
5
+
6
+ def truncate(self, pos=None): ...
7
+
8
+ def flush(self): ...
9
+
10
+ def close(self): ...
11
+
12
+ def seekable(self): ...
13
+
14
+ def readable(self): ...
15
+
16
+ def writable(self): ...
17
+
18
+ @property
19
+ def closed(self): ...
20
+
21
+ def __enter__(self): ...
22
+
23
+ def __exit__(self, *args): ...
24
+
25
+ def fileno(self): ...
26
+
27
+ def isatty(self): ...
28
+
29
+ def readline(self, size=-1): ...
30
+
31
+ def readlines(self, hint=None): ...
32
+
33
+ def writelines(self, lines): ...
34
+
35
+
36
+ class RawIOBase(IOBase):
37
+ def read(self, size=-1): ...
38
+
39
+ def readall(self): ...
40
+
41
+ def readinto(self, b): ...
42
+
43
+ def write(self, b): ...
44
+
45
+
46
+ class BufferedIOBase(IOBase):
47
+ def read(self, size=-1): ...
48
+
49
+ def read1(self, size=-1): ...
50
+
51
+ def readinto(self, b): ...
52
+
53
+ def readinto1(self, b): ...
54
+
55
+ def write(self, b): ...
56
+
57
+ def detach(self): ...
58
+
59
+
60
+ class TextIOBase(IOBase):
61
+ def read(self, size=-1): ...
62
+
63
+ def write(self, s): ...
64
+
65
+ def truncate(self, pos=None): ...
66
+
67
+ def readline(self): ...
68
+
69
+ def detach(self): ...
70
+
71
+ @property
72
+ def encoding(self): ...
73
+
74
+ @property
75
+ def newlines(self): ...
76
+
77
+ @property
78
+ def errors(self): ...