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.
@@ -30,18 +30,32 @@ jobs:
30
30
  runs-on: ubuntu-latest
31
31
  strategy:
32
32
  matrix:
33
- python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
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-version }}
50
+ run: rye pin ${{ matrix.settings.python }}
41
51
  - name: Sync dependencies
42
52
  run: rye sync
43
53
  - name: Test with pytest
44
- run: rye run pytest --cov=ovld --cov-report term-missing
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.python-version == '3.12' }}
60
+ if: ${{ matrix.settings.coverage }}
47
61
  run: rye run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ovld
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: Overloading Python functions
5
5
  Author-email: Olivier Breuleux <breuleux@gmail.com>
6
6
  License-Expression: MIT
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.6"
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>=0.1.6",
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]
@@ -22,3 +22,4 @@ pluggy==1.5.0
22
22
  pytest==8.3.2
23
23
  # via pytest-cov
24
24
  pytest-cov==5.0.0
25
+ uv==0.2.30
@@ -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
+ ]
@@ -115,6 +115,8 @@ class MultiTypeMap(dict):
115
115
  def transform(self, obj):
116
116
  if isinstance(obj, GenericAlias):
117
117
  return type[obj.__origin__]
118
+ elif obj is typing.Any:
119
+ return type[object]
118
120
  elif isinstance(obj, type):
119
121
  return type[obj]
120
122
  else:
@@ -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
@@ -0,0 +1,11 @@
1
+ from typing import Any
2
+
3
+ from ovld import ovld
4
+
5
+
6
+ @ovld
7
+ def test(x: type[object]):
8
+ return "yes"
9
+
10
+
11
+ print(test(Any))
@@ -1,3 +0,0 @@
1
- from .core import *
2
- from .utils import *
3
- from .version import version as __version__
@@ -1 +0,0 @@
1
- version = "0.3.6"
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