ovld 0.3.3__py3-none-any.whl → 0.3.5__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
@@ -12,6 +12,19 @@ try:
12
12
  except ImportError: # pragma: no cover
13
13
  UnionType = None
14
14
 
15
+
16
+ try:
17
+ from types import GenericAlias
18
+ except ImportError: # pragma: no cover
19
+
20
+ class GenericAliasMC(type):
21
+ def __instancecheck__(cls, obj):
22
+ return hasattr(obj, "__origin__")
23
+
24
+ class GenericAlias(metaclass=GenericAliasMC):
25
+ pass
26
+
27
+
15
28
  from .mro import compose_mro
16
29
  from .utils import BOOTSTRAP, MISSING, keyword_decorator
17
30
 
@@ -39,8 +52,13 @@ class TypeMap(dict):
39
52
 
40
53
  def register(self, obj_t, handler):
41
54
  """Register a handler for the given object type."""
55
+ if isinstance(obj_t, str):
56
+ obj_t = eval(obj_t, getattr(handler[0], "__globals__", {}))
57
+
42
58
  self.clear()
43
- if not is_type_of_type(obj_t):
59
+ if is_type_of_type(obj_t):
60
+ self.types.add(obj_t.__args__[0])
61
+ else:
44
62
  self.types.add(obj_t)
45
63
  s = self.entries.setdefault(obj_t, set())
46
64
  s.add(handler)
@@ -54,6 +72,8 @@ class TypeMap(dict):
54
72
  results = {}
55
73
  if is_type_of_type(obj_t):
56
74
  mro = [type[t] for t in compose_mro(obj_t.__args__[0], self.types)]
75
+ mro.append(type)
76
+ mro.append(object)
57
77
  else:
58
78
  mro = compose_mro(obj_t, self.types)
59
79
  for lvl, cls in enumerate(reversed(mro)):
@@ -93,7 +113,9 @@ class MultiTypeMap(dict):
93
113
  self.key_error = key_error
94
114
 
95
115
  def transform(self, obj):
96
- if isinstance(obj, type):
116
+ if isinstance(obj, GenericAlias):
117
+ return type[obj.__origin__]
118
+ elif isinstance(obj, type):
97
119
  return type[obj]
98
120
  else:
99
121
  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.5"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ovld
3
- Version: 0.3.3
3
+ Version: 0.3.5
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=CshFjuUcDtxhrFh2xFSDte8wNKTbu48xnQEmumKFEiI,33146
3
+ ovld/mro.py,sha256=Dof3wj-BLcV-T-Jm9tK6zqptp_JGo5lxgyRq99AvY1k,5006
4
+ ovld/utils.py,sha256=8kINtHrWdC0bNVccxYIkHBaGFk_YFpjtnjAa9GyXNmA,3861
5
+ ovld/version.py,sha256=M3X4I0aWn4g3ogkdyZ0rLSIZT87vxO8b-C9xRS5wkSk,18
6
+ ovld-0.3.5.dist-info/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
7
+ ovld-0.3.5.dist-info/METADATA,sha256=cO3RiKeqES82nfAiRn-1C0fel4q9AJSZaR6iEilLecg,9439
8
+ ovld-0.3.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ ovld-0.3.5.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