ovld 0.3.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ovld
3
- Version: 0.3.7
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.7"
3
+ version = "0.3.8"
4
4
  description = "Overloading Python functions"
5
5
  authors = [
6
6
  { name = "Olivier Breuleux", email = "breuleux@gmail.com" }
@@ -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"
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.7"
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