ovld 0.5.5__tar.gz → 0.5.6__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.5.5 → ovld-0.5.6}/PKG-INFO +1 -1
- {ovld-0.5.5 → ovld-0.5.6}/pyproject.toml +1 -1
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/dependent.py +2 -9
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/mro.py +6 -1
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/recode.py +1 -3
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/typemap.py +1 -5
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/types.py +6 -7
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/utils.py +29 -0
- ovld-0.5.6/src/ovld/version.py +1 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_dependent.py +28 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld.py +13 -0
- {ovld-0.5.5 → ovld-0.5.6}/uv.lock +2 -2
- ovld-0.5.5/src/ovld/version.py +0 -1
- {ovld-0.5.5 → ovld-0.5.6}/.github/workflows/publish.yml +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/.github/workflows/python-package.yml +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/.gitignore +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/.python-version +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/.readthedocs.yaml +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/LICENSE +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/README.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/__init__.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/common.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/conftest.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_add.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_ast.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_calc.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_fib.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_multer.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_regexp.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_trivial.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/benchmarks/test_tweaknum.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/codegen.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/compare.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/dependent.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/features.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/index.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/medley.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/types.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/docs/usage.md +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/mkdocs.yml +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/__init__.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/abc.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/codegen.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/core.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/medley.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/py.typed +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/src/ovld/signatures.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/__init__.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/modules/gingerbread.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_abc.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_dataclass_gen.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_method.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_method_metaclass.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_method_per_instance.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_simple.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen/test_variant_generation.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_codegen.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_examples.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_global.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_medley.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_mro.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld/test_display.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld/test_display_more.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld/test_doc.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld/test_doc2.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_ovld/test_method_doc.txt +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_typemap.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_types.py +0 -0
- {ovld-0.5.5 → ovld-0.5.6}/tests/test_utils.py +0 -0
@@ -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
|
@@ -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
|
|
@@ -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)
|
@@ -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):
|
@@ -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
|
|
@@ -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
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "0.5.6"
|
@@ -350,3 +350,31 @@ def test_keyed_plus_other():
|
|
350
350
|
assert f(0, 50) == "yes"
|
351
351
|
assert f(3, 50) == "yes"
|
352
352
|
assert f(0, 150) == "no"
|
353
|
+
|
354
|
+
|
355
|
+
class Lettered(type):
|
356
|
+
def __instancecheck__(cls, x):
|
357
|
+
return cls.letter in (getattr(x, "__name__", None) or str(x))
|
358
|
+
|
359
|
+
|
360
|
+
LetterF = Lettered("LetterF", (), {"letter": "f"})
|
361
|
+
LetterX = Lettered("LetterX", (), {"letter": "x"})
|
362
|
+
|
363
|
+
|
364
|
+
def test_arbitrary_instancecheck():
|
365
|
+
@ovld
|
366
|
+
def f(x: LetterX):
|
367
|
+
return "X-TREME"
|
368
|
+
|
369
|
+
@ovld
|
370
|
+
def f(x: LetterF):
|
371
|
+
return "fudged"
|
372
|
+
|
373
|
+
@ovld
|
374
|
+
def f(x: object):
|
375
|
+
return False
|
376
|
+
|
377
|
+
assert f(next) == "X-TREME"
|
378
|
+
assert f("wow") is False
|
379
|
+
assert f("extreme") == "X-TREME"
|
380
|
+
assert f(filter) == "fudged"
|
@@ -324,6 +324,19 @@ def test_optional():
|
|
324
324
|
assert f(1.0) == "f"
|
325
325
|
|
326
326
|
|
327
|
+
def test_none():
|
328
|
+
@ovld
|
329
|
+
def f(x: None):
|
330
|
+
return "null"
|
331
|
+
|
332
|
+
@ovld
|
333
|
+
def f(x: object):
|
334
|
+
return "X"
|
335
|
+
|
336
|
+
assert f(None) == "null"
|
337
|
+
assert f(123) == "X"
|
338
|
+
|
339
|
+
|
327
340
|
def test_abstract_types():
|
328
341
|
from collections.abc import Iterable
|
329
342
|
|
@@ -167,7 +167,7 @@ name = "importlib-metadata"
|
|
167
167
|
version = "8.7.0"
|
168
168
|
source = { registry = "https://pypi.org/simple" }
|
169
169
|
dependencies = [
|
170
|
-
{ name = "zipp" },
|
170
|
+
{ name = "zipp", marker = "python_full_version < '3.10'" },
|
171
171
|
]
|
172
172
|
sdist = { url = "https://files.pythonhosted.org/packages/76/66/650a33bd90f786193e4de4b3ad86ea60b53c89b669a5c7be931fac31cdb0/importlib_metadata-8.7.0.tar.gz", hash = "sha256:d13b81ad223b890aa16c5471f2ac3056cf76c5f10f82d6f9292f0b415f389000", size = 56641 }
|
173
173
|
wheels = [
|
@@ -366,7 +366,7 @@ wheels = [
|
|
366
366
|
|
367
367
|
[[package]]
|
368
368
|
name = "ovld"
|
369
|
-
version = "0.5.
|
369
|
+
version = "0.5.5"
|
370
370
|
source = { editable = "." }
|
371
371
|
|
372
372
|
[package.dev-dependencies]
|
ovld-0.5.5/src/ovld/version.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
version = "0.5.5"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|