ovld 0.5.5__py3-none-any.whl → 0.5.6__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/dependent.py CHANGED
@@ -15,22 +15,15 @@ from .types import (
15
15
  Intersection,
16
16
  Order,
17
17
  clsstring,
18
- get_args,
19
18
  normalize_type,
20
19
  subclasscheck,
21
20
  typeorder,
22
21
  )
23
22
 
24
23
 
25
- def is_dependent(t):
26
- if isinstance(t, DependentType):
27
- return True
28
- elif any(is_dependent(subt) for subt in get_args(t)):
29
- return True
30
- return False
31
-
32
-
33
24
  class DependentType(type):
25
+ __dependent__ = True
26
+
34
27
  exclusive_type = False
35
28
  keyable_type = False
36
29
  bound_is_name = False
ovld/mro.py CHANGED
@@ -3,7 +3,7 @@ from enum import Enum
3
3
  from graphlib import TopologicalSorter
4
4
  from typing import get_args, get_origin
5
5
 
6
- from .utils import UnionTypes
6
+ from .utils import UnionTypes, is_dependent
7
7
 
8
8
 
9
9
  class Order(Enum):
@@ -123,6 +123,11 @@ def subclasscheck(t1, t2):
123
123
  ):
124
124
  return result
125
125
 
126
+ if is_dependent(t2):
127
+ # t2's instancecheck could return anything, and unless it defines
128
+ # __is_supertype__ or __is_subtype__ the bound devolves to object
129
+ return True
130
+
126
131
  if t2 in UnionTypes:
127
132
  return isinstance(t1, t2)
128
133
 
ovld/recode.py CHANGED
@@ -12,7 +12,7 @@ from .codegen import (
12
12
  rename_function,
13
13
  transfer_function,
14
14
  )
15
- from .utils import MISSING, NameDatabase, SpecialForm, UsageError, subtler_type
15
+ from .utils import MISSING, NameDatabase, SpecialForm, UsageError, is_dependent, subtler_type
16
16
 
17
17
  recurse = SpecialForm("recurse")
18
18
  call_next = SpecialForm("call_next")
@@ -160,8 +160,6 @@ def generate_dispatch(ov, arganal):
160
160
 
161
161
 
162
162
  def generate_dependent_dispatch(tup, handlers, next_call, slf, name, err, nerr):
163
- from .dependent import is_dependent
164
-
165
163
  def to_dict(tup):
166
164
  return dict(
167
165
  entry if isinstance(entry, tuple) else (i, entry) for i, entry in enumerate(tup)
ovld/typemap.py CHANGED
@@ -6,7 +6,7 @@ from types import CodeType
6
6
 
7
7
  from .mro import sort_types
8
8
  from .recode import generate_dependent_dispatch
9
- from .utils import MISSING, CodegenInProgress, subtler_type
9
+ from .utils import MISSING, CodegenInProgress, is_dependent, subtler_type
10
10
 
11
11
 
12
12
  class TypeMap(dict):
@@ -213,8 +213,6 @@ class MultiTypeMap(dict):
213
213
  sig: A Signature object.
214
214
  handler: A function to handle the tuple.
215
215
  """
216
- from .dependent import is_dependent
217
-
218
216
  self.clear()
219
217
 
220
218
  obj_t_tup = sig.types
@@ -251,8 +249,6 @@ class MultiTypeMap(dict):
251
249
  print(f"{'':{width - 2}} @ {co.co_filename}:{co.co_firstlineno}")
252
250
 
253
251
  def display_resolution(self, *args, **kwargs):
254
- from .dependent import is_dependent
255
-
256
252
  def dependent_match(tup, args):
257
253
  for t, a in zip(tup, args):
258
254
  if isinstance(t, tuple):
ovld/types.py CHANGED
@@ -10,14 +10,9 @@ from .codegen import Code
10
10
  from .mro import Order, TypeRelationship, subclasscheck, typeorder
11
11
  from .recode import generate_checking_code
12
12
  from .typemap import TypeMap
13
- from .utils import UnionType, UnionTypes, UsageError, clsstring
13
+ from .utils import UnionType, UnionTypes, UsageError, clsstring, get_args
14
14
 
15
-
16
- def get_args(tp):
17
- args = getattr(tp, "__args__", None)
18
- if not isinstance(args, tuple):
19
- args = ()
20
- return args
15
+ NoneType = type(None)
21
16
 
22
17
 
23
18
  def eval_annotation(t, ctx, locals, catch=False):
@@ -90,6 +85,8 @@ class TypeNormalizer:
90
85
  raise UsageError(
91
86
  f"Dependent type {t} has not been given a type bound. Please use Dependent[<bound>, {t}] instead."
92
87
  )
88
+ elif t is None:
89
+ return NoneType
93
90
  else:
94
91
  return t
95
92
 
@@ -103,6 +100,8 @@ def _(self, t, fn):
103
100
 
104
101
 
105
102
  class MetaMC(type):
103
+ __dependent__ = False
104
+
106
105
  def __new__(T, name, handler):
107
106
  return super().__new__(T, name, (), {"_handler": handler})
108
107
 
ovld/utils.py CHANGED
@@ -4,6 +4,7 @@ import builtins
4
4
  import functools
5
5
  import re
6
6
  import typing
7
+ from abc import ABCMeta
7
8
  from itertools import count
8
9
 
9
10
  _builtins_dict = vars(builtins)
@@ -183,3 +184,31 @@ class NameDatabase:
183
184
  return name
184
185
 
185
186
  __getitem__ = get
187
+
188
+
189
+ def get_args(tp):
190
+ args = getattr(tp, "__args__", None)
191
+ if not isinstance(args, tuple):
192
+ args = ()
193
+ return args
194
+
195
+
196
+ _standard_instancechecks = {
197
+ type.__instancecheck__,
198
+ GenericAlias.__instancecheck__,
199
+ type(list[object]).__instancecheck__,
200
+ ABCMeta.__instancecheck__,
201
+ type(typing.Protocol).__instancecheck__,
202
+ }
203
+
204
+
205
+ def is_dependent(t):
206
+ if any(is_dependent(subt) for subt in get_args(t)):
207
+ return True
208
+ elif hasattr(t, "__dependent__"):
209
+ return t.__dependent__
210
+ elif not isinstance(t, type):
211
+ return False
212
+ elif type(t).__instancecheck__ not in _standard_instancechecks:
213
+ return True
214
+ return False
ovld/version.py CHANGED
@@ -1 +1 @@
1
- version = "0.5.5"
1
+ version = "0.5.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ovld
3
- Version: 0.5.5
3
+ Version: 0.5.6
4
4
  Summary: Overloading Python functions
5
5
  Project-URL: Homepage, https://ovld.readthedocs.io/en/latest/
6
6
  Project-URL: Documentation, https://ovld.readthedocs.io/en/latest/
@@ -0,0 +1,18 @@
1
+ ovld/__init__.py,sha256=JuCM8Sj65gobV0KYyLr95cSI23Pi6RYZ7X3_F3fdsSw,1821
2
+ ovld/abc.py,sha256=4qpZyYwI8dWgY1Oiv5FhdKg2uzNcyWxIpGmGJVcjXrs,1177
3
+ ovld/codegen.py,sha256=27tmamlanuTPDT-x31ISyqP0wGKW9BCFZJGVyq9qLg8,9728
4
+ ovld/core.py,sha256=HEREHblKcjM9dhFBr0FNwUCyec7o-9XjCsCfJ23SnNw,17544
5
+ ovld/dependent.py,sha256=JIgsc_5ddPH51_2IrZ6JW6bWE5RyrrrOwR2e9UvDhZ4,8922
6
+ ovld/medley.py,sha256=0fseIntzJRCPYXq-tmnxgy5ipNa4ZxR0D_6So0xstdQ,12729
7
+ ovld/mro.py,sha256=Aw1r5Zz7V9cVBDwWzQ-WNnbpBwoGztgbw3wLAyS6Y60,4863
8
+ ovld/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ ovld/recode.py,sha256=vXg9XLExp_9LdAHO0JWR4wvwHhpOLu2Xcrg9ZYg1nms,16407
10
+ ovld/signatures.py,sha256=Q8JucSOun0ESGx14aWtHtBzLEiM6FxY5HP3imyqXoDo,8984
11
+ ovld/typemap.py,sha256=EH3oM_QmX-SHLEz14saVrQtRlqG_ltPyJGORLvcGOFk,13520
12
+ ovld/types.py,sha256=CRL6Vuzg5moXgAAhIj2698GvZoyF4HWbUDYz2hKt6us,13373
13
+ ovld/utils.py,sha256=cyy9pcuMhmo1_UdPonH9JT6B9QlI4oH6_JK89cM3_gk,5046
14
+ ovld/version.py,sha256=FtfC8ptaFH0Unc72bPRynMH_N62bxa4tnazGgIcgnTY,18
15
+ ovld-0.5.6.dist-info/METADATA,sha256=NuqYyUraNAzGzrl8XUVET_xO6xBSzbPhy5F5AtzITWk,9383
16
+ ovld-0.5.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
+ ovld-0.5.6.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
18
+ ovld-0.5.6.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- ovld/__init__.py,sha256=JuCM8Sj65gobV0KYyLr95cSI23Pi6RYZ7X3_F3fdsSw,1821
2
- ovld/abc.py,sha256=4qpZyYwI8dWgY1Oiv5FhdKg2uzNcyWxIpGmGJVcjXrs,1177
3
- ovld/codegen.py,sha256=27tmamlanuTPDT-x31ISyqP0wGKW9BCFZJGVyq9qLg8,9728
4
- ovld/core.py,sha256=HEREHblKcjM9dhFBr0FNwUCyec7o-9XjCsCfJ23SnNw,17544
5
- ovld/dependent.py,sha256=h3j4oQYTQfGqMzggWlLV6TpojX_GtYRFWAO0GcMB0Zs,9085
6
- ovld/medley.py,sha256=0fseIntzJRCPYXq-tmnxgy5ipNa4ZxR0D_6So0xstdQ,12729
7
- ovld/mro.py,sha256=LXHkP_28J9EwM9IrXYraYI0qm4dHWkDKCgkXn0u_YCo,4655
8
- ovld/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- ovld/recode.py,sha256=ZVqD3sCu_myaFj3lKPCMjFBf1pTdTAAd3NJdsqtLYuU,16434
10
- ovld/signatures.py,sha256=Q8JucSOun0ESGx14aWtHtBzLEiM6FxY5HP3imyqXoDo,8984
11
- ovld/typemap.py,sha256=5Pro1Ee60fH4L7NW7k5nbN5EfDygA0LFHcI6o3mCagI,13596
12
- ovld/types.py,sha256=0hkhAR5_5793NABdrM-fP1dSJBhYof85FILKqVP2YMg,13392
13
- ovld/utils.py,sha256=fD20RWWGwI3Z8q5DvrdCPDA_Wm1uiyfCZLLL2IM9ZJw,4348
14
- ovld/version.py,sha256=v9c8T1qB0Dxuq0vdkPvh2bpcAlRxlK4BxHPcACDymFw,18
15
- ovld-0.5.5.dist-info/METADATA,sha256=K1dYchmA245qK_Kji4j7t-d8CTgriiem6JM_MnigdXM,9383
16
- ovld-0.5.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- ovld-0.5.5.dist-info/licenses/LICENSE,sha256=cSwNTIzd1cbI89xt3PeZZYJP2y3j8Zus4bXgo4svpX8,1066
18
- ovld-0.5.5.dist-info/RECORD,,
File without changes