ovld 0.3.6__tar.gz → 0.3.8__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.3.8/.bsync-snap-20220324145902.852076 +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/.github/workflows/python-package.yml +18 -4
- {ovld-0.3.6 → ovld-0.3.8}/PKG-INFO +1 -1
- ovld-0.3.8/bench.py +136 -0
- {ovld-0.3.6 → ovld-0.3.8}/pyproject.toml +3 -2
- {ovld-0.3.6 → ovld-0.3.8}/requirements-dev.lock +1 -0
- ovld-0.3.8/src/ovld/__init__.py +48 -0
- {ovld-0.3.6 → ovld-0.3.8}/src/ovld/core.py +2 -0
- ovld-0.3.8/src/ovld/version.py +1 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/test_ovld.py +16 -0
- ovld-0.3.8/x.py +11 -0
- ovld-0.3.6/src/ovld/__init__.py +0 -3
- ovld-0.3.6/src/ovld/version.py +0 -1
- {ovld-0.3.6 → ovld-0.3.8}/.envrc +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/.gitignore +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/.python-version +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/LICENSE +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/README.md +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/requirements.lock +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/src/ovld/mro.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/src/ovld/utils.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/__init__.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/modules/gingerbread.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/test_global.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/test_typemap.py +0 -0
- {ovld-0.3.6 → ovld-0.3.8}/tests/test_utils.py +0 -0
Binary file
|
@@ -30,18 +30,32 @@ jobs:
|
|
30
30
|
runs-on: ubuntu-latest
|
31
31
|
strategy:
|
32
32
|
matrix:
|
33
|
-
|
33
|
+
settings:
|
34
|
+
- python: '3.8'
|
35
|
+
coverage: false
|
36
|
+
- python: '3.9'
|
37
|
+
coverage: false
|
38
|
+
- python: '3.10'
|
39
|
+
coverage: false
|
40
|
+
- python: '3.11'
|
41
|
+
coverage: false
|
42
|
+
- python: '3.12'
|
43
|
+
coverage: true
|
34
44
|
steps:
|
35
45
|
- name: Check out the code
|
36
46
|
uses: actions/checkout@v3
|
37
47
|
- name: Install rye
|
38
48
|
uses: eifinger/setup-rye@v4
|
39
49
|
- name: Pin Python version
|
40
|
-
run: rye pin ${{ matrix.python
|
50
|
+
run: rye pin ${{ matrix.settings.python }}
|
41
51
|
- name: Sync dependencies
|
42
52
|
run: rye sync
|
43
53
|
- name: Test with pytest
|
44
|
-
|
54
|
+
if: ${{ !matrix.settings.coverage }}
|
55
|
+
run: rye run pytest
|
56
|
+
- name: Test with pytest and coverage
|
57
|
+
if: ${{ matrix.settings.coverage }}
|
58
|
+
run: rye run pytest --cov=src --cov-report term-missing
|
45
59
|
- name: Verify coverage
|
46
|
-
if: ${{ matrix.
|
60
|
+
if: ${{ matrix.settings.coverage }}
|
47
61
|
run: rye run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
|
ovld-0.3.8/bench.py
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
import timeit
|
2
|
+
|
3
|
+
from multimethod import multimethod
|
4
|
+
from multipledispatch import dispatch
|
5
|
+
from ovld import ovld
|
6
|
+
|
7
|
+
# OVLD
|
8
|
+
|
9
|
+
|
10
|
+
@ovld
|
11
|
+
def smap(x: list, y: list):
|
12
|
+
"""One."""
|
13
|
+
return [smap(a, b) for a, b in zip(x, y)]
|
14
|
+
|
15
|
+
|
16
|
+
@ovld
|
17
|
+
def smap(x: tuple, y: tuple):
|
18
|
+
return tuple(smap(a, b) for a, b in zip(x, y))
|
19
|
+
|
20
|
+
|
21
|
+
@ovld
|
22
|
+
def smap(x: dict, y: dict):
|
23
|
+
return {k: smap(v, y[k]) for k, v in x.items()}
|
24
|
+
|
25
|
+
|
26
|
+
@ovld
|
27
|
+
def smap(x: object, y: object):
|
28
|
+
return x + y
|
29
|
+
|
30
|
+
|
31
|
+
# OVLD B
|
32
|
+
|
33
|
+
|
34
|
+
@ovld
|
35
|
+
def smap_b(self, x: list, y: list):
|
36
|
+
"""Two."""
|
37
|
+
return [self(a, b) for a, b in zip(x, y)]
|
38
|
+
|
39
|
+
|
40
|
+
@ovld
|
41
|
+
def smap_b(self, x: tuple, y: tuple):
|
42
|
+
return tuple(self(a, b) for a, b in zip(x, y))
|
43
|
+
|
44
|
+
|
45
|
+
@ovld
|
46
|
+
def smap_b(self, x: dict, y: dict):
|
47
|
+
return {k: self(v, y[k]) for k, v in x.items()}
|
48
|
+
|
49
|
+
|
50
|
+
@ovld
|
51
|
+
def smap_b(self, x: object, y: object):
|
52
|
+
return x + y
|
53
|
+
|
54
|
+
|
55
|
+
# multimethods
|
56
|
+
|
57
|
+
|
58
|
+
@multimethod
|
59
|
+
def smap_mm(x: list, y: list):
|
60
|
+
"""Three."""
|
61
|
+
return [smap_mm(a, b) for a, b in zip(x, y)]
|
62
|
+
|
63
|
+
|
64
|
+
@multimethod
|
65
|
+
def smap_mm(x: tuple, y: tuple):
|
66
|
+
return tuple(smap_mm(a, b) for a, b in zip(x, y))
|
67
|
+
|
68
|
+
|
69
|
+
@multimethod
|
70
|
+
def smap_mm(x: dict, y: dict):
|
71
|
+
return {k: smap_mm(v, y[k]) for k, v in x.items()}
|
72
|
+
|
73
|
+
|
74
|
+
@multimethod
|
75
|
+
def smap_mm(x: object, y: object):
|
76
|
+
return x + y
|
77
|
+
|
78
|
+
|
79
|
+
# multipledispatch
|
80
|
+
|
81
|
+
|
82
|
+
@dispatch(list, list)
|
83
|
+
def smap_md(x, y):
|
84
|
+
"""Four."""
|
85
|
+
return [smap_md(a, b) for a, b in zip(x, y)]
|
86
|
+
|
87
|
+
|
88
|
+
@dispatch(tuple, tuple)
|
89
|
+
def smap_md(x, y):
|
90
|
+
return tuple(smap_md(a, b) for a, b in zip(x, y))
|
91
|
+
|
92
|
+
|
93
|
+
@dispatch(dict, dict)
|
94
|
+
def smap_md(x, y):
|
95
|
+
return {k: smap_md(v, y[k]) for k, v in x.items()}
|
96
|
+
|
97
|
+
|
98
|
+
@dispatch(object, object)
|
99
|
+
def smap_md(x, y):
|
100
|
+
return x + y
|
101
|
+
|
102
|
+
|
103
|
+
# isinstance
|
104
|
+
|
105
|
+
|
106
|
+
def smap_ii(x, y):
|
107
|
+
"""Five."""
|
108
|
+
if isinstance(x, dict) and isinstance(y, dict):
|
109
|
+
return {k: smap_ii(v, y[k]) for k, v in x.items()}
|
110
|
+
elif isinstance(x, tuple) and isinstance(y, tuple):
|
111
|
+
return tuple(smap_ii(a, b) for a, b in zip(x, y))
|
112
|
+
elif isinstance(x, list) and isinstance(y, list):
|
113
|
+
return [smap_ii(a, b) for a, b in zip(x, y)]
|
114
|
+
else:
|
115
|
+
return x + y
|
116
|
+
|
117
|
+
|
118
|
+
# multipledispatch
|
119
|
+
|
120
|
+
|
121
|
+
A = {"xs": list(range(50)), "ys": ("o", (6, 7))}
|
122
|
+
B = {"xs": list(range(10, 60)), "ys": ("x", (7, 6))}
|
123
|
+
|
124
|
+
print(smap(A, B))
|
125
|
+
print(smap_mm(A, B))
|
126
|
+
print(smap_md(A, B))
|
127
|
+
print(smap_ii(A, B))
|
128
|
+
print(smap_b(A, B))
|
129
|
+
|
130
|
+
# breakpoint()
|
131
|
+
|
132
|
+
print("smap_ov\t", timeit.timeit(lambda: smap(A, B), number=10000))
|
133
|
+
print("smap_mm\t", timeit.timeit(lambda: smap_mm(A, B), number=10000))
|
134
|
+
print("smap_md\t", timeit.timeit(lambda: smap_md(A, B), number=10000))
|
135
|
+
print("smap_ii\t", timeit.timeit(lambda: smap_ii(A, B), number=10000))
|
136
|
+
print("smap_b\t", timeit.timeit(lambda: smap_b(A, B), number=10000))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "ovld"
|
3
|
-
version = "0.3.
|
3
|
+
version = "0.3.8"
|
4
4
|
description = "Overloading Python functions"
|
5
5
|
authors = [
|
6
6
|
{ name = "Olivier Breuleux", email = "breuleux@gmail.com" }
|
@@ -19,9 +19,10 @@ build-backend = "hatchling.build"
|
|
19
19
|
[tool.rye]
|
20
20
|
managed = true
|
21
21
|
dev-dependencies = [
|
22
|
-
"codefind
|
22
|
+
"codefind~=0.1.6",
|
23
23
|
"pytest>=8.3.2",
|
24
24
|
"pytest-cov>=5.0.0",
|
25
|
+
"uv>=0.2.30",
|
25
26
|
]
|
26
27
|
|
27
28
|
[tool.hatch.metadata]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
from .core import (
|
2
|
+
MultiTypeMap,
|
3
|
+
Ovld,
|
4
|
+
OvldBase,
|
5
|
+
OvldCall,
|
6
|
+
OvldMC,
|
7
|
+
TypeMap,
|
8
|
+
extend_super,
|
9
|
+
is_ovld,
|
10
|
+
ovld,
|
11
|
+
ovld_dispatch,
|
12
|
+
)
|
13
|
+
from .utils import (
|
14
|
+
BOOTSTRAP,
|
15
|
+
MISSING,
|
16
|
+
Dataclass,
|
17
|
+
Named,
|
18
|
+
deferred,
|
19
|
+
exactly,
|
20
|
+
has_attribute,
|
21
|
+
keyword_decorator,
|
22
|
+
meta,
|
23
|
+
strict_subclass,
|
24
|
+
)
|
25
|
+
from .version import version as __version__
|
26
|
+
|
27
|
+
__all__ = [
|
28
|
+
"MultiTypeMap",
|
29
|
+
"Ovld",
|
30
|
+
"OvldBase",
|
31
|
+
"OvldCall",
|
32
|
+
"OvldMC",
|
33
|
+
"TypeMap",
|
34
|
+
"extend_super",
|
35
|
+
"is_ovld",
|
36
|
+
"ovld",
|
37
|
+
"ovld_dispatch",
|
38
|
+
"BOOTSTRAP",
|
39
|
+
"MISSING",
|
40
|
+
"Dataclass",
|
41
|
+
"Named",
|
42
|
+
"deferred",
|
43
|
+
"exactly",
|
44
|
+
"has_attribute",
|
45
|
+
"meta",
|
46
|
+
"keyword_decorator",
|
47
|
+
"strict_subclass",
|
48
|
+
]
|
@@ -0,0 +1 @@
|
|
1
|
+
version = "0.3.8"
|
@@ -1108,6 +1108,22 @@ def test_generic_type_argument():
|
|
1108
1108
|
assert f(dict[str, int]) == "dict"
|
1109
1109
|
|
1110
1110
|
|
1111
|
+
@pytest.mark.skipif(
|
1112
|
+
sys.version_info < (3, 9),
|
1113
|
+
reason="type[...] syntax requires python3.9 or higher",
|
1114
|
+
)
|
1115
|
+
def test_any():
|
1116
|
+
@ovld
|
1117
|
+
def f(t: type[dict]):
|
1118
|
+
return "no"
|
1119
|
+
|
1120
|
+
@ovld
|
1121
|
+
def f(t: type[object]):
|
1122
|
+
return "yes"
|
1123
|
+
|
1124
|
+
assert f(typing.Any) == "yes"
|
1125
|
+
|
1126
|
+
|
1111
1127
|
@pytest.mark.skipif(
|
1112
1128
|
sys.version_info < (3, 9),
|
1113
1129
|
reason="type[...] syntax requires python3.9 or higher",
|
ovld-0.3.8/x.py
ADDED
ovld-0.3.6/src/ovld/__init__.py
DELETED
ovld-0.3.6/src/ovld/version.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
version = "0.3.6"
|
{ovld-0.3.6 → ovld-0.3.8}/.envrc
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
|