ovld 0.4.2__tar.gz → 0.4.3__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.4.2 → ovld-0.4.3}/PKG-INFO +1 -1
- {ovld-0.4.2 → ovld-0.4.3}/pyproject.toml +1 -1
- {ovld-0.4.2 → ovld-0.4.3}/reddit.md +1 -1
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/__init__.py +8 -0
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/dependent.py +16 -9
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/mro.py +16 -15
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/types.py +26 -14
- ovld-0.4.3/src/ovld/version.py +1 -0
- ovld-0.4.3/tests/test_mro.py +112 -0
- {ovld-0.4.2 → ovld-0.4.3}/todo.q +3 -0
- {ovld-0.4.2 → ovld-0.4.3}/uv.lock +1 -1
- ovld-0.4.2/src/ovld/version.py +0 -1
- ovld-0.4.2/tests/test_mro.py +0 -51
- {ovld-0.4.2 → ovld-0.4.3}/.bsync-snap-20220324145902.852076 +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.bsync-snap-20240916114026.355340 +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.envrc +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.github/workflows/python-package.yml +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.gitignore +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.python-version +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/.readthedocs.yaml +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/LICENSE +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/README.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/add.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/anal.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/bench/requirements.txt +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/bench.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchd.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/__init__.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/common.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_add.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_ast.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_calc.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_fib.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_multer.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_trivial.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/benchmarks/test_tweaknum.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/cloz.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/data.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/didi.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/compare.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/dependent.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/features.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/index.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/types.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/docs/usage.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/doo.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/edges.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/explore.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/facto.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/gen_comparison_table.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/gentest.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/hello.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/hntest.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/klos.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/mkdocs.yml +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/nxt.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.0-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.0.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.1-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.1.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.2-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.2.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.3-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.3.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.4-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.4.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.5-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.5.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.6-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.6.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.7-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.7.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.8-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.8.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.9-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.1.9.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.0-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.0.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.1-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.1.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.10-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.10.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.11-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.11.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.2-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.2.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.3-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.3.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.4-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.4.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.5-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.5.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.6-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.6.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.7-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.7.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.8-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.8.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.9-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.2.9.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.0-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.0.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.1-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.1.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.2-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.2.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.3-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.3.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.4-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.4.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.5-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.5.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.8-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.8.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.9-py3-none-any.whl +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/old-dist/ovld-0.3.9.tar.gz +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/one_two_three.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/outoftheway.toml +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/reddit.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/core.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/recode.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/typemap.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/src/ovld/utils.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/stuff.md +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tb.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tensor.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/__init__.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/modules/gingerbread.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_dependent.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_examples.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_global.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_ovld/test_display.txt +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_ovld/test_doc.txt +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_ovld/test_doc2.txt +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_ovld/test_method_doc.txt +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_ovld.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_typemap.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_types.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/tests/test_utils.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/toot.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/typo.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/world.yaml +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/x.py +0 -0
- {ovld-0.4.2 → ovld-0.4.3}/zaggo +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
## What My Project Does
|
2
2
|
|
3
|
-
|
3
|
+
[ovld](https://github.com/breuleux/ovld) implements multiple dispatch in Python. This lets you define multiple versions of the same function with different type signatures.
|
4
4
|
|
5
5
|
For example:
|
6
6
|
|
@@ -15,6 +15,11 @@ from .dependent import (
|
|
15
15
|
ParametrizedDependentType,
|
16
16
|
dependent_check,
|
17
17
|
)
|
18
|
+
from .mro import (
|
19
|
+
TypeRelationship,
|
20
|
+
subclasscheck,
|
21
|
+
typeorder,
|
22
|
+
)
|
18
23
|
from .recode import call_next, recurse
|
19
24
|
from .typemap import (
|
20
25
|
MultiTypeMap,
|
@@ -66,6 +71,9 @@ __all__ = [
|
|
66
71
|
"Intersection",
|
67
72
|
"StrictSubclass",
|
68
73
|
"class_check",
|
74
|
+
"subclasscheck",
|
75
|
+
"typeorder",
|
76
|
+
"TypeRelationship",
|
69
77
|
"parametrized_class_check",
|
70
78
|
"keyword_decorator",
|
71
79
|
"call_next",
|
@@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Any, Mapping, TypeVar, Union
|
|
7
7
|
from .types import (
|
8
8
|
Intersection,
|
9
9
|
Order,
|
10
|
-
TypeRelationship,
|
11
10
|
normalize_type,
|
12
11
|
subclasscheck,
|
13
12
|
typeorder,
|
@@ -67,26 +66,34 @@ class DependentType:
|
|
67
66
|
def codegen(self):
|
68
67
|
return CodeGen("{this}.check({arg})", {"this": self})
|
69
68
|
|
70
|
-
def
|
69
|
+
def __type_order__(self, other):
|
71
70
|
if isinstance(other, DependentType):
|
72
71
|
order = typeorder(self.bound, other.bound)
|
73
72
|
if order is Order.SAME:
|
74
73
|
# It isn't fully deterministic which of these will be called
|
75
74
|
# because of set ordering between the types we compare
|
76
75
|
if self < other: # pragma: no cover
|
77
|
-
return
|
76
|
+
return Order.LESS
|
78
77
|
elif other < self: # pragma: no cover
|
79
|
-
return
|
78
|
+
return Order.MORE
|
80
79
|
else:
|
81
|
-
return
|
80
|
+
return Order.NONE
|
82
81
|
else: # pragma: no cover
|
83
|
-
return
|
84
|
-
elif
|
82
|
+
return order
|
83
|
+
elif subclasscheck(other, self.bound) or subclasscheck(
|
85
84
|
self.bound, other
|
86
85
|
):
|
87
|
-
return
|
86
|
+
return Order.LESS
|
88
87
|
else:
|
89
|
-
return
|
88
|
+
return Order.NONE
|
89
|
+
|
90
|
+
def __is_supertype__(self, other):
|
91
|
+
if isinstance(other, DependentType):
|
92
|
+
return False
|
93
|
+
elif subclasscheck(other, self.bound):
|
94
|
+
return True
|
95
|
+
else:
|
96
|
+
return False
|
90
97
|
|
91
98
|
def __lt__(self, other):
|
92
99
|
return False
|
@@ -22,7 +22,8 @@ class Order(Enum):
|
|
22
22
|
@dataclass
|
23
23
|
class TypeRelationship:
|
24
24
|
order: Order
|
25
|
-
|
25
|
+
supertype: bool = NotImplemented
|
26
|
+
subtype: bool = NotImplemented
|
26
27
|
|
27
28
|
|
28
29
|
def _issubclass(t1, t2):
|
@@ -48,19 +49,16 @@ def typeorder(t1, t2):
|
|
48
49
|
if t1 == t2:
|
49
50
|
return Order.SAME
|
50
51
|
|
51
|
-
t1 = getattr(t1, "__proxy_for__", t1)
|
52
|
-
t2 = getattr(t2, "__proxy_for__", t2)
|
53
|
-
|
54
52
|
if (
|
55
|
-
hasattr(t1, "
|
56
|
-
and (result := t1.
|
53
|
+
hasattr(t1, "__type_order__")
|
54
|
+
and (result := t1.__type_order__(t2)) is not NotImplemented
|
57
55
|
):
|
58
|
-
return result
|
56
|
+
return result
|
59
57
|
elif (
|
60
|
-
hasattr(t2, "
|
61
|
-
and (result := t2.
|
58
|
+
hasattr(t2, "__type_order__")
|
59
|
+
and (result := t2.__type_order__(t1)) is not NotImplemented
|
62
60
|
):
|
63
|
-
return result.
|
61
|
+
return result.opposite()
|
64
62
|
|
65
63
|
o1 = getattr(t1, "__origin__", None)
|
66
64
|
o2 = getattr(t2, "__origin__", None)
|
@@ -135,14 +133,17 @@ def subclasscheck(t1, t2):
|
|
135
133
|
if t1 == t2:
|
136
134
|
return True
|
137
135
|
|
138
|
-
|
139
|
-
|
136
|
+
if (
|
137
|
+
hasattr(t2, "__is_supertype__")
|
138
|
+
and (result := t2.__is_supertype__(t1)) is not NotImplemented
|
139
|
+
):
|
140
|
+
return result
|
140
141
|
|
141
142
|
if (
|
142
|
-
hasattr(
|
143
|
-
and (result :=
|
143
|
+
hasattr(t1, "__is_subtype__")
|
144
|
+
and (result := t1.__is_subtype__(t2)) is not NotImplemented
|
144
145
|
):
|
145
|
-
return result
|
146
|
+
return result
|
146
147
|
|
147
148
|
o1 = getattr(t1, "__origin__", None)
|
148
149
|
o2 = getattr(t2, "__origin__", None)
|
@@ -61,19 +61,31 @@ class MetaMC(type):
|
|
61
61
|
def __init__(cls, name, order):
|
62
62
|
pass
|
63
63
|
|
64
|
-
def
|
65
|
-
|
66
|
-
if isinstance(
|
67
|
-
return
|
64
|
+
def __type_order__(cls, other):
|
65
|
+
results = cls.order(other)
|
66
|
+
if isinstance(results, TypeRelationship):
|
67
|
+
return results.order
|
68
68
|
else:
|
69
|
-
return
|
69
|
+
return NotImplemented
|
70
|
+
|
71
|
+
def __is_supertype__(cls, other):
|
72
|
+
results = cls.order(other)
|
73
|
+
if isinstance(results, bool):
|
74
|
+
return results
|
75
|
+
elif isinstance(results, TypeRelationship):
|
76
|
+
return results.supertype
|
77
|
+
else: # pragma: no cover
|
78
|
+
return NotImplemented
|
79
|
+
|
80
|
+
def __is_subtype__(cls, other):
|
81
|
+
results = cls.order(other)
|
82
|
+
if isinstance(results, TypeRelationship):
|
83
|
+
return results.subtype
|
84
|
+
else: # pragma: no cover
|
85
|
+
return NotImplemented
|
70
86
|
|
71
87
|
def __subclasscheck__(cls, sub):
|
72
|
-
|
73
|
-
if isinstance(result, TypeRelationship):
|
74
|
-
return result.order in (Order.MORE, Order.SAME)
|
75
|
-
else:
|
76
|
-
return result
|
88
|
+
return cls.__is_supertype__(sub)
|
77
89
|
|
78
90
|
|
79
91
|
def class_check(condition):
|
@@ -164,7 +176,7 @@ def Exactly(cls, base_cls):
|
|
164
176
|
"""Match the class but not its subclasses."""
|
165
177
|
return TypeRelationship(
|
166
178
|
order=Order.LESS if cls is base_cls else typeorder(base_cls, cls),
|
167
|
-
|
179
|
+
supertype=cls is base_cls,
|
168
180
|
)
|
169
181
|
|
170
182
|
|
@@ -184,11 +196,11 @@ def Intersection(cls, *classes):
|
|
184
196
|
matches = all(subclasscheck(cls, t) for t in classes)
|
185
197
|
compare = [x for t in classes if (x := typeorder(t, cls)) is not Order.NONE]
|
186
198
|
if not compare:
|
187
|
-
return TypeRelationship(Order.NONE,
|
199
|
+
return TypeRelationship(Order.NONE, supertype=matches)
|
188
200
|
elif any(x is Order.LESS or x is Order.SAME for x in compare):
|
189
|
-
return TypeRelationship(Order.LESS,
|
201
|
+
return TypeRelationship(Order.LESS, supertype=matches)
|
190
202
|
else:
|
191
|
-
return TypeRelationship(Order.MORE,
|
203
|
+
return TypeRelationship(Order.MORE, supertype=matches)
|
192
204
|
|
193
205
|
|
194
206
|
@parametrized_class_check
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "0.4.3"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
try:
|
2
|
+
from types import UnionType
|
3
|
+
except ImportError: # pragma: no cover
|
4
|
+
UnionType = None
|
5
|
+
|
6
|
+
import sys
|
7
|
+
from typing import Union
|
8
|
+
|
9
|
+
from ovld.dependent import Dependent
|
10
|
+
from ovld.mro import Order, subclasscheck, typeorder
|
11
|
+
|
12
|
+
|
13
|
+
def identity(x):
|
14
|
+
return x
|
15
|
+
|
16
|
+
|
17
|
+
class A:
|
18
|
+
pass
|
19
|
+
|
20
|
+
|
21
|
+
class B(A):
|
22
|
+
pass
|
23
|
+
|
24
|
+
|
25
|
+
class Prox:
|
26
|
+
_cls = object
|
27
|
+
|
28
|
+
def __class_getitem__(cls, other):
|
29
|
+
return type(f"Prox[{other.__name__}]", (Prox,), {"_cls": other})
|
30
|
+
|
31
|
+
@classmethod
|
32
|
+
def __is_supertype__(cls, other):
|
33
|
+
return subclasscheck(other, cls._cls)
|
34
|
+
|
35
|
+
@classmethod
|
36
|
+
def __is_subtype__(cls, other):
|
37
|
+
return subclasscheck(cls._cls, other)
|
38
|
+
|
39
|
+
@classmethod
|
40
|
+
def __type_order__(cls, other):
|
41
|
+
return typeorder(cls._cls, other)
|
42
|
+
|
43
|
+
|
44
|
+
def test_subclasscheck():
|
45
|
+
assert subclasscheck(B, A)
|
46
|
+
assert not subclasscheck(A, B)
|
47
|
+
assert subclasscheck(A, A)
|
48
|
+
assert subclasscheck(A, object)
|
49
|
+
assert subclasscheck(A, Union[A, int])
|
50
|
+
assert subclasscheck(int, Union[A, int])
|
51
|
+
|
52
|
+
|
53
|
+
def test_subclasscheck_generic():
|
54
|
+
assert subclasscheck(list[int], list[int])
|
55
|
+
assert subclasscheck(list[int], list[object])
|
56
|
+
assert not subclasscheck(list[object], list[int])
|
57
|
+
|
58
|
+
|
59
|
+
def test_subclasscheck_type():
|
60
|
+
assert subclasscheck(type[int], type[object])
|
61
|
+
|
62
|
+
|
63
|
+
def test_subclasscheck_type_union():
|
64
|
+
if sys.version_info >= (3, 10):
|
65
|
+
assert subclasscheck(type[int | str], type[UnionType])
|
66
|
+
assert subclasscheck(type[Union[int, str]], type[Union])
|
67
|
+
assert subclasscheck(type[Union], object)
|
68
|
+
assert not subclasscheck(object, type[Union])
|
69
|
+
|
70
|
+
|
71
|
+
def test_typeorder_type_union():
|
72
|
+
if sys.version_info >= (3, 10):
|
73
|
+
assert typeorder(type[int | str], type[UnionType]) is Order.LESS
|
74
|
+
assert typeorder(type[Union[int, str]], type[Union]) is Order.LESS
|
75
|
+
assert typeorder(object, type[Union]) is Order.MORE
|
76
|
+
|
77
|
+
|
78
|
+
def test_subclasscheck_dependent():
|
79
|
+
assert subclasscheck(B, Dependent[A, identity])
|
80
|
+
assert not subclasscheck(
|
81
|
+
Dependent[int, identity], Dependent[float, identity]
|
82
|
+
)
|
83
|
+
|
84
|
+
|
85
|
+
def test_typeorder_dependent():
|
86
|
+
assert typeorder(Dependent[int, identity], float) is Order.NONE
|
87
|
+
assert (
|
88
|
+
typeorder(Dependent[int, identity], Dependent[A, identity])
|
89
|
+
is Order.NONE
|
90
|
+
)
|
91
|
+
assert (
|
92
|
+
typeorder(Dependent[int, identity], Dependent[float, identity])
|
93
|
+
is Order.NONE
|
94
|
+
)
|
95
|
+
|
96
|
+
|
97
|
+
def test_subclasscheck_proxy():
|
98
|
+
assert subclasscheck(Prox[int], int)
|
99
|
+
assert subclasscheck(int, Prox[int])
|
100
|
+
assert subclasscheck(Prox[int], Prox)
|
101
|
+
assert not subclasscheck(Prox, Prox[int])
|
102
|
+
|
103
|
+
assert subclasscheck(Prox[B], A)
|
104
|
+
assert not subclasscheck(Prox[A], B)
|
105
|
+
assert subclasscheck(B, Prox[A])
|
106
|
+
assert not subclasscheck(A, Prox[B])
|
107
|
+
assert subclasscheck(Prox[B], Prox[A])
|
108
|
+
|
109
|
+
assert typeorder(Prox[int], int) is Order.SAME
|
110
|
+
assert typeorder(int, Prox[int]) is Order.SAME
|
111
|
+
assert typeorder(Prox[int], Prox) is Order.LESS
|
112
|
+
assert typeorder(Prox, Prox[int]) is Order.MORE
|
{ovld-0.4.2 → ovld-0.4.3}/todo.q
RENAMED
@@ -13,6 +13,9 @@
|
|
13
13
|
* Optimize the itertools.product in mro
|
14
14
|
* Context variable to turn off code generation
|
15
15
|
* Add second priority level corresponding to definition order
|
16
|
+
* Support `tuple[t1, t2, ...]
|
17
|
+
* Support `TypedDict
|
18
|
+
* Support `dict[kt, vt], `list[et], etc.
|
16
19
|
|
17
20
|
|
18
21
|
= DONE
|
ovld-0.4.2/src/ovld/version.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
version = "0.4.2"
|
ovld-0.4.2/tests/test_mro.py
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
try:
|
2
|
-
from types import UnionType
|
3
|
-
except ImportError: # pragma: no cover
|
4
|
-
UnionType = None
|
5
|
-
|
6
|
-
import sys
|
7
|
-
from typing import Union
|
8
|
-
|
9
|
-
from ovld.mro import Order, subclasscheck, typeorder
|
10
|
-
|
11
|
-
|
12
|
-
class A:
|
13
|
-
pass
|
14
|
-
|
15
|
-
|
16
|
-
class B(A):
|
17
|
-
pass
|
18
|
-
|
19
|
-
|
20
|
-
def test_subclasscheck():
|
21
|
-
assert subclasscheck(B, A)
|
22
|
-
assert not subclasscheck(A, B)
|
23
|
-
assert subclasscheck(A, A)
|
24
|
-
assert subclasscheck(A, object)
|
25
|
-
assert subclasscheck(A, Union[A, int])
|
26
|
-
assert subclasscheck(int, Union[A, int])
|
27
|
-
|
28
|
-
|
29
|
-
def test_subclasscheck_generic():
|
30
|
-
assert subclasscheck(list[int], list[int])
|
31
|
-
assert subclasscheck(list[int], list[object])
|
32
|
-
assert not subclasscheck(list[object], list[int])
|
33
|
-
|
34
|
-
|
35
|
-
def test_subclasscheck_type():
|
36
|
-
assert subclasscheck(type[int], type[object])
|
37
|
-
|
38
|
-
|
39
|
-
def test_subclasscheck_type_union():
|
40
|
-
if sys.version_info >= (3, 10):
|
41
|
-
assert subclasscheck(type[int | str], type[UnionType])
|
42
|
-
assert subclasscheck(type[Union[int, str]], type[Union])
|
43
|
-
assert subclasscheck(type[Union], object)
|
44
|
-
assert not subclasscheck(object, type[Union])
|
45
|
-
|
46
|
-
|
47
|
-
def test_typeorder_type_union():
|
48
|
-
if sys.version_info >= (3, 10):
|
49
|
-
assert typeorder(type[int | str], type[UnionType]) is Order.LESS
|
50
|
-
assert typeorder(type[Union[int, str]], type[Union]) is Order.LESS
|
51
|
-
assert typeorder(object, type[Union]) is Order.MORE
|
File without changes
|
File without changes
|
{ovld-0.4.2 → ovld-0.4.3}/.envrc
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{ovld-0.4.2 → ovld-0.4.3}/add.py
RENAMED
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
|
{ovld-0.4.2 → ovld-0.4.3}/doo.py
RENAMED
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
|
{ovld-0.4.2 → ovld-0.4.3}/nxt.py
RENAMED
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
|
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
|
{ovld-0.4.2 → ovld-0.4.3}/tb.py
RENAMED
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
|
{ovld-0.4.2 → ovld-0.4.3}/x.py
RENAMED
File without changes
|
{ovld-0.4.2 → ovld-0.4.3}/zaggo
RENAMED
File without changes
|