ovld 0.3.3__tar.gz → 0.3.4__tar.gz
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-0.3.3 → ovld-0.3.4}/PKG-INFO +1 -1
- {ovld-0.3.3 → ovld-0.3.4}/ovld/core.py +20 -3
- {ovld-0.3.3 → ovld-0.3.4}/ovld/utils.py +13 -0
- ovld-0.3.4/ovld/version.py +1 -0
- {ovld-0.3.3 → ovld-0.3.4}/pyproject.toml +1 -1
- ovld-0.3.3/ovld/version.py +0 -1
- {ovld-0.3.3 → ovld-0.3.4}/LICENSE +0 -0
- {ovld-0.3.3 → ovld-0.3.4}/README.md +0 -0
- {ovld-0.3.3 → ovld-0.3.4}/ovld/__init__.py +0 -0
- {ovld-0.3.3 → ovld-0.3.4}/ovld/mro.py +0 -0
@@ -8,10 +8,18 @@ import typing
|
|
8
8
|
from types import FunctionType
|
9
9
|
|
10
10
|
try:
|
11
|
-
from types import UnionType
|
11
|
+
from types import GenericAlias, UnionType
|
12
12
|
except ImportError: # pragma: no cover
|
13
13
|
UnionType = None
|
14
14
|
|
15
|
+
class GenericAliasMC(type):
|
16
|
+
def __instancecheck__(cls, obj):
|
17
|
+
return hasattr(obj, "__origin__")
|
18
|
+
|
19
|
+
class GenericAlias(metaclass=GenericAliasMC):
|
20
|
+
pass
|
21
|
+
|
22
|
+
|
15
23
|
from .mro import compose_mro
|
16
24
|
from .utils import BOOTSTRAP, MISSING, keyword_decorator
|
17
25
|
|
@@ -39,8 +47,13 @@ class TypeMap(dict):
|
|
39
47
|
|
40
48
|
def register(self, obj_t, handler):
|
41
49
|
"""Register a handler for the given object type."""
|
50
|
+
if isinstance(obj_t, str):
|
51
|
+
obj_t = eval(obj_t, getattr(handler[0], "__globals__", {}))
|
52
|
+
|
42
53
|
self.clear()
|
43
|
-
if
|
54
|
+
if is_type_of_type(obj_t):
|
55
|
+
self.types.add(obj_t.__args__[0])
|
56
|
+
else:
|
44
57
|
self.types.add(obj_t)
|
45
58
|
s = self.entries.setdefault(obj_t, set())
|
46
59
|
s.add(handler)
|
@@ -54,6 +67,8 @@ class TypeMap(dict):
|
|
54
67
|
results = {}
|
55
68
|
if is_type_of_type(obj_t):
|
56
69
|
mro = [type[t] for t in compose_mro(obj_t.__args__[0], self.types)]
|
70
|
+
mro.append(type)
|
71
|
+
mro.append(object)
|
57
72
|
else:
|
58
73
|
mro = compose_mro(obj_t, self.types)
|
59
74
|
for lvl, cls in enumerate(reversed(mro)):
|
@@ -93,7 +108,9 @@ class MultiTypeMap(dict):
|
|
93
108
|
self.key_error = key_error
|
94
109
|
|
95
110
|
def transform(self, obj):
|
96
|
-
if isinstance(obj,
|
111
|
+
if isinstance(obj, GenericAlias):
|
112
|
+
return type[obj.__origin__]
|
113
|
+
elif isinstance(obj, type):
|
97
114
|
return type[obj]
|
98
115
|
else:
|
99
116
|
return type(obj)
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
import functools
|
4
4
|
import sys
|
5
|
+
from dataclasses import dataclass
|
6
|
+
from typing import Protocol, runtime_checkable
|
5
7
|
|
6
8
|
|
7
9
|
class Named:
|
@@ -143,9 +145,20 @@ def has_attribute(*attrs):
|
|
143
145
|
return check
|
144
146
|
|
145
147
|
|
148
|
+
@runtime_checkable
|
149
|
+
@dataclass
|
150
|
+
class Dataclass(Protocol):
|
151
|
+
@classmethod
|
152
|
+
def __subclasshook__(cls, subclass):
|
153
|
+
return hasattr(subclass, "__dataclass_fields__") and hasattr(
|
154
|
+
subclass, "__dataclass_params__"
|
155
|
+
)
|
156
|
+
|
157
|
+
|
146
158
|
__all__ = [
|
147
159
|
"BOOTSTRAP",
|
148
160
|
"MISSING",
|
161
|
+
"Dataclass",
|
149
162
|
"Named",
|
150
163
|
"deferred",
|
151
164
|
"exactly",
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "0.3.4"
|
ovld-0.3.3/ovld/version.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
version = "0.3.3"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|