ovld 0.4.2__py3-none-any.whl → 0.4.3__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.
- ovld/__init__.py +8 -0
- ovld/dependent.py +16 -9
- ovld/mro.py +16 -15
- ovld/types.py +26 -14
- ovld/version.py +1 -1
- {ovld-0.4.2.dist-info → ovld-0.4.3.dist-info}/METADATA +1 -1
- ovld-0.4.3.dist-info/RECORD +13 -0
- ovld-0.4.2.dist-info/RECORD +0 -13
- {ovld-0.4.2.dist-info → ovld-0.4.3.dist-info}/WHEEL +0 -0
- {ovld-0.4.2.dist-info → ovld-0.4.3.dist-info}/licenses/LICENSE +0 -0
ovld/__init__.py
CHANGED
@@ -15,6 +15,11 @@ from .dependent import (
|
|
15
15
|
ParametrizedDependentType,
|
16
16
|
dependent_check,
|
17
17
|
)
|
18
|
+
from .mro import (
|
19
|
+
TypeRelationship,
|
20
|
+
subclasscheck,
|
21
|
+
typeorder,
|
22
|
+
)
|
18
23
|
from .recode import call_next, recurse
|
19
24
|
from .typemap import (
|
20
25
|
MultiTypeMap,
|
@@ -66,6 +71,9 @@ __all__ = [
|
|
66
71
|
"Intersection",
|
67
72
|
"StrictSubclass",
|
68
73
|
"class_check",
|
74
|
+
"subclasscheck",
|
75
|
+
"typeorder",
|
76
|
+
"TypeRelationship",
|
69
77
|
"parametrized_class_check",
|
70
78
|
"keyword_decorator",
|
71
79
|
"call_next",
|
ovld/dependent.py
CHANGED
@@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Any, Mapping, TypeVar, Union
|
|
7
7
|
from .types import (
|
8
8
|
Intersection,
|
9
9
|
Order,
|
10
|
-
TypeRelationship,
|
11
10
|
normalize_type,
|
12
11
|
subclasscheck,
|
13
12
|
typeorder,
|
@@ -67,26 +66,34 @@ class DependentType:
|
|
67
66
|
def codegen(self):
|
68
67
|
return CodeGen("{this}.check({arg})", {"this": self})
|
69
68
|
|
70
|
-
def
|
69
|
+
def __type_order__(self, other):
|
71
70
|
if isinstance(other, DependentType):
|
72
71
|
order = typeorder(self.bound, other.bound)
|
73
72
|
if order is Order.SAME:
|
74
73
|
# It isn't fully deterministic which of these will be called
|
75
74
|
# because of set ordering between the types we compare
|
76
75
|
if self < other: # pragma: no cover
|
77
|
-
return
|
76
|
+
return Order.LESS
|
78
77
|
elif other < self: # pragma: no cover
|
79
|
-
return
|
78
|
+
return Order.MORE
|
80
79
|
else:
|
81
|
-
return
|
80
|
+
return Order.NONE
|
82
81
|
else: # pragma: no cover
|
83
|
-
return
|
84
|
-
elif
|
82
|
+
return order
|
83
|
+
elif subclasscheck(other, self.bound) or subclasscheck(
|
85
84
|
self.bound, other
|
86
85
|
):
|
87
|
-
return
|
86
|
+
return Order.LESS
|
88
87
|
else:
|
89
|
-
return
|
88
|
+
return Order.NONE
|
89
|
+
|
90
|
+
def __is_supertype__(self, other):
|
91
|
+
if isinstance(other, DependentType):
|
92
|
+
return False
|
93
|
+
elif subclasscheck(other, self.bound):
|
94
|
+
return True
|
95
|
+
else:
|
96
|
+
return False
|
90
97
|
|
91
98
|
def __lt__(self, other):
|
92
99
|
return False
|
ovld/mro.py
CHANGED
@@ -22,7 +22,8 @@ class Order(Enum):
|
|
22
22
|
@dataclass
|
23
23
|
class TypeRelationship:
|
24
24
|
order: Order
|
25
|
-
|
25
|
+
supertype: bool = NotImplemented
|
26
|
+
subtype: bool = NotImplemented
|
26
27
|
|
27
28
|
|
28
29
|
def _issubclass(t1, t2):
|
@@ -48,19 +49,16 @@ def typeorder(t1, t2):
|
|
48
49
|
if t1 == t2:
|
49
50
|
return Order.SAME
|
50
51
|
|
51
|
-
t1 = getattr(t1, "__proxy_for__", t1)
|
52
|
-
t2 = getattr(t2, "__proxy_for__", t2)
|
53
|
-
|
54
52
|
if (
|
55
|
-
hasattr(t1, "
|
56
|
-
and (result := t1.
|
53
|
+
hasattr(t1, "__type_order__")
|
54
|
+
and (result := t1.__type_order__(t2)) is not NotImplemented
|
57
55
|
):
|
58
|
-
return result
|
56
|
+
return result
|
59
57
|
elif (
|
60
|
-
hasattr(t2, "
|
61
|
-
and (result := t2.
|
58
|
+
hasattr(t2, "__type_order__")
|
59
|
+
and (result := t2.__type_order__(t1)) is not NotImplemented
|
62
60
|
):
|
63
|
-
return result.
|
61
|
+
return result.opposite()
|
64
62
|
|
65
63
|
o1 = getattr(t1, "__origin__", None)
|
66
64
|
o2 = getattr(t2, "__origin__", None)
|
@@ -135,14 +133,17 @@ def subclasscheck(t1, t2):
|
|
135
133
|
if t1 == t2:
|
136
134
|
return True
|
137
135
|
|
138
|
-
|
139
|
-
|
136
|
+
if (
|
137
|
+
hasattr(t2, "__is_supertype__")
|
138
|
+
and (result := t2.__is_supertype__(t1)) is not NotImplemented
|
139
|
+
):
|
140
|
+
return result
|
140
141
|
|
141
142
|
if (
|
142
|
-
hasattr(
|
143
|
-
and (result :=
|
143
|
+
hasattr(t1, "__is_subtype__")
|
144
|
+
and (result := t1.__is_subtype__(t2)) is not NotImplemented
|
144
145
|
):
|
145
|
-
return result
|
146
|
+
return result
|
146
147
|
|
147
148
|
o1 = getattr(t1, "__origin__", None)
|
148
149
|
o2 = getattr(t2, "__origin__", None)
|
ovld/types.py
CHANGED
@@ -61,19 +61,31 @@ class MetaMC(type):
|
|
61
61
|
def __init__(cls, name, order):
|
62
62
|
pass
|
63
63
|
|
64
|
-
def
|
65
|
-
|
66
|
-
if isinstance(
|
67
|
-
return
|
64
|
+
def __type_order__(cls, other):
|
65
|
+
results = cls.order(other)
|
66
|
+
if isinstance(results, TypeRelationship):
|
67
|
+
return results.order
|
68
68
|
else:
|
69
|
-
return
|
69
|
+
return NotImplemented
|
70
|
+
|
71
|
+
def __is_supertype__(cls, other):
|
72
|
+
results = cls.order(other)
|
73
|
+
if isinstance(results, bool):
|
74
|
+
return results
|
75
|
+
elif isinstance(results, TypeRelationship):
|
76
|
+
return results.supertype
|
77
|
+
else: # pragma: no cover
|
78
|
+
return NotImplemented
|
79
|
+
|
80
|
+
def __is_subtype__(cls, other):
|
81
|
+
results = cls.order(other)
|
82
|
+
if isinstance(results, TypeRelationship):
|
83
|
+
return results.subtype
|
84
|
+
else: # pragma: no cover
|
85
|
+
return NotImplemented
|
70
86
|
|
71
87
|
def __subclasscheck__(cls, sub):
|
72
|
-
|
73
|
-
if isinstance(result, TypeRelationship):
|
74
|
-
return result.order in (Order.MORE, Order.SAME)
|
75
|
-
else:
|
76
|
-
return result
|
88
|
+
return cls.__is_supertype__(sub)
|
77
89
|
|
78
90
|
|
79
91
|
def class_check(condition):
|
@@ -164,7 +176,7 @@ def Exactly(cls, base_cls):
|
|
164
176
|
"""Match the class but not its subclasses."""
|
165
177
|
return TypeRelationship(
|
166
178
|
order=Order.LESS if cls is base_cls else typeorder(base_cls, cls),
|
167
|
-
|
179
|
+
supertype=cls is base_cls,
|
168
180
|
)
|
169
181
|
|
170
182
|
|
@@ -184,11 +196,11 @@ def Intersection(cls, *classes):
|
|
184
196
|
matches = all(subclasscheck(cls, t) for t in classes)
|
185
197
|
compare = [x for t in classes if (x := typeorder(t, cls)) is not Order.NONE]
|
186
198
|
if not compare:
|
187
|
-
return TypeRelationship(Order.NONE,
|
199
|
+
return TypeRelationship(Order.NONE, supertype=matches)
|
188
200
|
elif any(x is Order.LESS or x is Order.SAME for x in compare):
|
189
|
-
return TypeRelationship(Order.LESS,
|
201
|
+
return TypeRelationship(Order.LESS, supertype=matches)
|
190
202
|
else:
|
191
|
-
return TypeRelationship(Order.MORE,
|
203
|
+
return TypeRelationship(Order.MORE, supertype=matches)
|
192
204
|
|
193
205
|
|
194
206
|
@parametrized_class_check
|
ovld/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version = "0.4.
|
1
|
+
version = "0.4.3"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ovld/__init__.py,sha256=_MJizMQ-Ise8c53GCsC7f-MOhp-qcUd0bpvu8LUFp8M,1444
|
2
|
+
ovld/core.py,sha256=glexOiRU0ajoxFAQN6d69ToL6_cPvyv05Z7LEHqrJj8,25701
|
3
|
+
ovld/dependent.py,sha256=HZbn2uU1uby9D-5qmDSjwdUpIJPdBXYrCW82lpTrBS4,7289
|
4
|
+
ovld/mro.py,sha256=eNU8rMG3hVOA1h7cd2lo4mmXQQbAGI5ISERllOO8_Js,5598
|
5
|
+
ovld/recode.py,sha256=zxhyotuc73qzuN4NEN_rKxaqoA0SOH7KFtE2l_CRBFs,17963
|
6
|
+
ovld/typemap.py,sha256=gw8XvB-N_15Dr0-am0v17x1seNjYK5AxvUT9L36mWic,13630
|
7
|
+
ovld/types.py,sha256=zR5_W3iFZb5LfktjrGfCMa1-eAwlF-AyBeTwAX3JayU,6795
|
8
|
+
ovld/utils.py,sha256=V6Y8oZ6ojq8JaODL1rMZbU5L9QG0YSqHNYmpIFiwy3M,1294
|
9
|
+
ovld/version.py,sha256=qGkDKQTrLXZ0o-aafthub4OFvdwOI_7GN29zXzZj8zg,18
|
10
|
+
ovld-0.4.3.dist-info/METADATA,sha256=JxkPMmizv16TxE_gBQKClp29o8d_10FgFYsPVQ2Tvf0,7713
|
11
|
+
ovld-0.4.3.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
12
|
+
ovld-0.4.3.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
|
13
|
+
ovld-0.4.3.dist-info/RECORD,,
|
ovld-0.4.2.dist-info/RECORD
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
ovld/__init__.py,sha256=Vp9wbIy_opFmJx-vCcToQcIP3cWFIvgbfYHITyiwPLs,1305
|
2
|
-
ovld/core.py,sha256=glexOiRU0ajoxFAQN6d69ToL6_cPvyv05Z7LEHqrJj8,25701
|
3
|
-
ovld/dependent.py,sha256=QITsWu2uCwqkHE0tunETy8Jqwc272uoG5YM0I5yy0m4,7303
|
4
|
-
ovld/mro.py,sha256=rS0pCLLWwLUI0NdthpoJSrdvWR4-XgRfx1pLAvJde14,5586
|
5
|
-
ovld/recode.py,sha256=zxhyotuc73qzuN4NEN_rKxaqoA0SOH7KFtE2l_CRBFs,17963
|
6
|
-
ovld/typemap.py,sha256=gw8XvB-N_15Dr0-am0v17x1seNjYK5AxvUT9L36mWic,13630
|
7
|
-
ovld/types.py,sha256=Zeb7xhHbL4T7qIRHI-I_cjG61UIWrfZv_EwjwqhB-rY,6381
|
8
|
-
ovld/utils.py,sha256=V6Y8oZ6ojq8JaODL1rMZbU5L9QG0YSqHNYmpIFiwy3M,1294
|
9
|
-
ovld/version.py,sha256=OHlqRD04Kvw_CFYmiIVx7UuOJRTQKtAx1Bl4rkUYHJE,18
|
10
|
-
ovld-0.4.2.dist-info/METADATA,sha256=fV3vxTKRAjCUkRVNmzTW14VajGSl7P0b9NnG06cjUJk,7713
|
11
|
-
ovld-0.4.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
12
|
-
ovld-0.4.2.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
|
13
|
-
ovld-0.4.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|