ovld 0.3.3__py3-none-any.whl → 0.3.4__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/core.py CHANGED
@@ -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 not is_type_of_type(obj_t):
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, type):
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)
ovld/utils.py CHANGED
@@ -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",
ovld/version.py CHANGED
@@ -1 +1 @@
1
- version = "0.3.3"
1
+ version = "0.3.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ovld
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Overloading Python functions
5
5
  Home-page: https://github.com/breuleux/ovld
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ ovld/__init__.py,sha256=Wa7MHfDw0_AV7jwSwepntCeXzZheELkb8paxVnjp58Q,85
2
+ ovld/core.py,sha256=Iz9VMQAqRGsgZqwBkR8uNoBdnC0vp4RYhVDcMydcPlo,33078
3
+ ovld/mro.py,sha256=Dof3wj-BLcV-T-Jm9tK6zqptp_JGo5lxgyRq99AvY1k,5006
4
+ ovld/utils.py,sha256=8kINtHrWdC0bNVccxYIkHBaGFk_YFpjtnjAa9GyXNmA,3861
5
+ ovld/version.py,sha256=gFnDcL_GoJXrglbZytpscjJFX7Ge1G2_exIvsJP20D4,18
6
+ ovld-0.3.4.dist-info/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
7
+ ovld-0.3.4.dist-info/METADATA,sha256=1JtepDt_ZRKv07KGQb0DhymtG5OnYXXUyy1UEg4XHy4,9439
8
+ ovld-0.3.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ ovld-0.3.4.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- ovld/__init__.py,sha256=Wa7MHfDw0_AV7jwSwepntCeXzZheELkb8paxVnjp58Q,85
2
- ovld/core.py,sha256=uLRvhoXb0d8ide648_e1EsYdqDZZZtz3rLqVAsOdisw,32571
3
- ovld/mro.py,sha256=Dof3wj-BLcV-T-Jm9tK6zqptp_JGo5lxgyRq99AvY1k,5006
4
- ovld/utils.py,sha256=JT44u-OiFC2QBUylaubwKlgvvRS0EYPfykxgMbbIrMY,3521
5
- ovld/version.py,sha256=nlGXcobmeAmNzRkhqDLZxGFLcidRwZSZPlWcdlVyxvw,18
6
- ovld-0.3.3.dist-info/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
7
- ovld-0.3.3.dist-info/METADATA,sha256=vf9bZaiRGKrZzreiu_jvSFLkIzd4cyP6Agz4qarM4Zc,9439
8
- ovld-0.3.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
- ovld-0.3.3.dist-info/RECORD,,
File without changes
File without changes