ovld 0.4.0__py3-none-any.whl → 0.4.1__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 CHANGED
@@ -70,4 +70,5 @@ __all__ = [
70
70
  "keyword_decorator",
71
71
  "call_next",
72
72
  "recurse",
73
+ "__version__",
73
74
  ]
ovld/core.py CHANGED
@@ -20,12 +20,6 @@ from .typemap import MultiTypeMap, is_type_of_type
20
20
  from .types import normalize_type
21
21
  from .utils import UsageError, keyword_decorator
22
22
 
23
- try:
24
- from types import UnionType
25
- except ImportError: # pragma: no cover
26
- UnionType = None
27
-
28
-
29
23
  _current_id = itertools.count()
30
24
 
31
25
 
ovld/mro.py CHANGED
@@ -25,6 +25,16 @@ class TypeRelationship:
25
25
  matches: bool = None
26
26
 
27
27
 
28
+ def _issubclass(t1, t2):
29
+ try:
30
+ return issubclass(t1, t2)
31
+ except TypeError:
32
+ try:
33
+ return isinstance(t1, t2)
34
+ except TypeError: # pragma: no cover
35
+ return False
36
+
37
+
28
38
  def typeorder(t1, t2):
29
39
  """Order relation between two types.
30
40
 
@@ -56,6 +66,8 @@ def typeorder(t1, t2):
56
66
  o2 = getattr(t2, "__origin__", None)
57
67
 
58
68
  if o2 is typing.Union:
69
+ if t1 is typing.Union:
70
+ return Order.MORE
59
71
  compare = [
60
72
  x for t in t2.__args__ if (x := typeorder(t1, t)) is not Order.NONE
61
73
  ]
@@ -105,8 +117,8 @@ def typeorder(t1, t2):
105
117
  # Not sure when t1 != t2 and that happens
106
118
  return Order.SAME
107
119
 
108
- sx = issubclass(t1, t2)
109
- sy = issubclass(t2, t1)
120
+ sx = _issubclass(t1, t2)
121
+ sy = _issubclass(t2, t1)
110
122
  if sx and sy: # pragma: no cover
111
123
  # Not sure when t1 != t2 and that happens
112
124
  return Order.SAME
@@ -136,14 +148,23 @@ def subclasscheck(t1, t2):
136
148
  o2 = getattr(t2, "__origin__", None)
137
149
 
138
150
  if o2 is typing.Union:
139
- return any(subclasscheck(t1, t) for t in t2.__args__)
151
+ return t1 is typing.Union or any(
152
+ subclasscheck(t1, t) for t in t2.__args__
153
+ )
140
154
  elif o1 is typing.Union:
141
- return all(subclasscheck(t, t2) for t in t1.__args__)
155
+ return t2 is typing.Union or all(
156
+ subclasscheck(t, t2) for t in t1.__args__
157
+ )
158
+
159
+ if not isinstance(o1, type):
160
+ o1 = None
161
+ if not isinstance(o2, type):
162
+ o2 = None
142
163
 
143
164
  if o1 or o2:
144
165
  o1 = o1 or t1
145
166
  o2 = o2 or t2
146
- if issubclass(o1, o2):
167
+ if _issubclass(o1, o2):
147
168
  if o2 is t2: # pragma: no cover
148
169
  return True
149
170
  else:
@@ -157,7 +178,7 @@ def subclasscheck(t1, t2):
157
178
  else:
158
179
  return False
159
180
  else:
160
- return issubclass(t1, t2)
181
+ return _issubclass(t1, t2)
161
182
 
162
183
 
163
184
  def sort_types(cls, avail):
ovld/version.py CHANGED
@@ -1 +1 @@
1
- version = "0.4.0"
1
+ version = "0.4.1"
@@ -1,7 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ovld
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Overloading Python functions
5
+ Project-URL: Homepage, https://ovld.readthedocs.io/en/latest/
6
+ Project-URL: Documentation, https://ovld.readthedocs.io/en/latest/
7
+ Project-URL: Repository, https://github.com/breuleux/ovld
5
8
  Author-email: Olivier Breuleux <breuleux@gmail.com>
6
9
  License-Expression: MIT
7
10
  License-File: LICENSE
@@ -0,0 +1,13 @@
1
+ ovld/__init__.py,sha256=Vp9wbIy_opFmJx-vCcToQcIP3cWFIvgbfYHITyiwPLs,1305
2
+ ovld/core.py,sha256=S6YSbZk5ajKvdVqn5NyuduDAU_moBylZGmpNskQE7XI,25397
3
+ ovld/dependent.py,sha256=QITsWu2uCwqkHE0tunETy8Jqwc272uoG5YM0I5yy0m4,7303
4
+ ovld/mro.py,sha256=rS0pCLLWwLUI0NdthpoJSrdvWR4-XgRfx1pLAvJde14,5586
5
+ ovld/recode.py,sha256=Vc97Nv1j2GWuitLOzIuIhpscZ4gaOJQP3hLNp8SGTQ8,17890
6
+ ovld/typemap.py,sha256=U_BmXtts1oYVa6gI3cgGHMX5kFcCJY_mt_cjWvDo3jQ,12979
7
+ ovld/types.py,sha256=Zeb7xhHbL4T7qIRHI-I_cjG61UIWrfZv_EwjwqhB-rY,6381
8
+ ovld/utils.py,sha256=V6Y8oZ6ojq8JaODL1rMZbU5L9QG0YSqHNYmpIFiwy3M,1294
9
+ ovld/version.py,sha256=FBeN5tbWV0BpBmjJ3d3pzaNRlEg_Blp421Tbg8X3cAI,18
10
+ ovld-0.4.1.dist-info/METADATA,sha256=OOhqZjiT-T6jb-c0iATIElVxfZbZ62qDcuJQcxvHMQM,7713
11
+ ovld-0.4.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
+ ovld-0.4.1.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
13
+ ovld-0.4.1.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- ovld/__init__.py,sha256=nF8ymgr8dSL2WvDpOXVxqDuEGUywbkiCGr4ICumMD8U,1286
2
- ovld/core.py,sha256=siahCDuw78n02-2g7TGI1GerrGvPxT0zPouN6Z30Z-g,25497
3
- ovld/dependent.py,sha256=QITsWu2uCwqkHE0tunETy8Jqwc272uoG5YM0I5yy0m4,7303
4
- ovld/mro.py,sha256=dNuVW5DIOT8TJtY4vEpxT4q3R8fQxJ8UyDQSD9oFYYo,5116
5
- ovld/recode.py,sha256=Vc97Nv1j2GWuitLOzIuIhpscZ4gaOJQP3hLNp8SGTQ8,17890
6
- ovld/typemap.py,sha256=U_BmXtts1oYVa6gI3cgGHMX5kFcCJY_mt_cjWvDo3jQ,12979
7
- ovld/types.py,sha256=Zeb7xhHbL4T7qIRHI-I_cjG61UIWrfZv_EwjwqhB-rY,6381
8
- ovld/utils.py,sha256=V6Y8oZ6ojq8JaODL1rMZbU5L9QG0YSqHNYmpIFiwy3M,1294
9
- ovld/version.py,sha256=yhiWOz0HoJGRRI9-JQ2eh_0AbByy-6psK08-kpTSHJw,18
10
- ovld-0.4.0.dist-info/METADATA,sha256=4NkzmXbqa8ZNCwESYT4U8yILZyaIlw1rcghfCyaT50U,7526
11
- ovld-0.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
12
- ovld-0.4.0.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
13
- ovld-0.4.0.dist-info/RECORD,,
File without changes