scaevola 1.0.16__tar.gz → 1.1.1__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.
- scaevola-1.1.1/MANIFEST.in +1 -0
- {scaevola-1.0.16/src/scaevola.egg-info → scaevola-1.1.1}/PKG-INFO +1 -1
- {scaevola-1.0.16 → scaevola-1.1.1}/pyproject.toml +1 -1
- scaevola-1.1.1/src/scaevola/core/__init__.py +85 -0
- scaevola-1.1.1/src/scaevola/core/cfg.toml +20 -0
- scaevola-1.0.16/src/scaevola/tests/test_0.py → scaevola-1.1.1/src/scaevola/tests/test_doc.py +6 -9
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola/tests/test_op.py +1 -0
- scaevola-1.0.16/src/scaevola/tests/test_slots.py → scaevola-1.1.1/src/scaevola/tests/test_slots_Scaevola.py +2 -2
- scaevola-1.1.1/src/scaevola/tests/test_slots_auto.py +36 -0
- {scaevola-1.0.16 → scaevola-1.1.1/src/scaevola.egg-info}/PKG-INFO +1 -1
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola.egg-info/SOURCES.txt +5 -3
- scaevola-1.0.16/MANIFEST.in +0 -0
- scaevola-1.0.16/src/scaevola/core.py +0 -72
- {scaevola-1.0.16 → scaevola-1.1.1}/LICENSE.txt +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/README.rst +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/setup.cfg +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola/__init__.py +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola/tests/__init__.py +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola.egg-info/dependency_links.txt +0 -0
- {scaevola-1.0.16 → scaevola-1.1.1}/src/scaevola.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include src/scaevola *.toml
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
import functools
|
|
3
|
+
import operator
|
|
4
|
+
import tomllib
|
|
5
|
+
import types
|
|
6
|
+
from importlib import resources
|
|
7
|
+
from typing import *
|
|
8
|
+
|
|
9
|
+
__all__ = ["Scaevola", "auto", "getfuncnames", "makefunc"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Util(enum.Enum):
|
|
13
|
+
"This enum provides a singleton."
|
|
14
|
+
util = None
|
|
15
|
+
|
|
16
|
+
@functools.cached_property
|
|
17
|
+
def data(self: Self) -> dict:
|
|
18
|
+
"This cached property holds the cfg data."
|
|
19
|
+
text: str = resources.read_text("scaevola.core", "cfg.toml")
|
|
20
|
+
ans: dict = tomllib.loads(text)
|
|
21
|
+
return ans
|
|
22
|
+
|
|
23
|
+
@functools.cached_property
|
|
24
|
+
def funcdata(self: Self) -> dict:
|
|
25
|
+
"This cached property holds the data for easy function making."
|
|
26
|
+
ans: dict = dict()
|
|
27
|
+
name: str
|
|
28
|
+
doc: str
|
|
29
|
+
inner: Callable
|
|
30
|
+
name = "__ge__"
|
|
31
|
+
doc = self.data["docs"]["ge"]
|
|
32
|
+
inner = operator.le
|
|
33
|
+
ans[name] = dict(doc=doc, inner=inner)
|
|
34
|
+
name = "__gt__"
|
|
35
|
+
doc = self.data["docs"]["gt"]
|
|
36
|
+
inner = operator.lt
|
|
37
|
+
ans[name] = dict(doc=doc, inner=inner)
|
|
38
|
+
name = "__rdivmod__"
|
|
39
|
+
doc = self.data["docs"]["rdivmod"]
|
|
40
|
+
inner = divmod
|
|
41
|
+
ans[name] = dict(doc=doc, inner=inner)
|
|
42
|
+
x: Any
|
|
43
|
+
y: Any
|
|
44
|
+
for x, y in self.data["operator"].items():
|
|
45
|
+
name = "__r%s__" % x.rstrip("_")
|
|
46
|
+
doc = self.data["docs"]["operator"] % y
|
|
47
|
+
inner = getattr(operator, x)
|
|
48
|
+
ans[name] = dict(doc=doc, inner=inner)
|
|
49
|
+
ans = dict(sorted(ans.items()))
|
|
50
|
+
return ans
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def auto(cls: type) -> type:
|
|
54
|
+
"This decorator implements all the righthand functions."
|
|
55
|
+
name: str
|
|
56
|
+
for name in getfuncnames():
|
|
57
|
+
if name not in cls.__dict__.keys():
|
|
58
|
+
makefunc(cls, name)
|
|
59
|
+
return cls
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def getfuncnames() -> list[str]:
|
|
63
|
+
"This function returns the names of all righthand functions."
|
|
64
|
+
return list(Util.util.funcdata.keys())
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def makefunc(cls: type, name: str) -> types.FunctionType:
|
|
68
|
+
"This function implements a certain righthand function."
|
|
69
|
+
inner: Callable = Util.util.funcdata[name]["inner"]
|
|
70
|
+
|
|
71
|
+
def outer(self: Self, other: Any) -> Any:
|
|
72
|
+
"This docstring will be overwritten."
|
|
73
|
+
return inner(type(self)(other), self)
|
|
74
|
+
|
|
75
|
+
outer.__doc__ = Util.util.funcdata[name]["doc"]
|
|
76
|
+
outer.__module__ = cls.__module__
|
|
77
|
+
outer.__name__ = name
|
|
78
|
+
outer.__qualname__ = cls.__qualname__ + "." + name
|
|
79
|
+
setattr(cls, name, outer)
|
|
80
|
+
return outer
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@auto
|
|
84
|
+
class Scaevola:
|
|
85
|
+
pass
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[docs]
|
|
2
|
+
operator = "This magic method implements other%sself."
|
|
3
|
+
ge = "This magic method implements self>=other."
|
|
4
|
+
gt = "This magic method implements self>other."
|
|
5
|
+
rdivmod = "This magic method implements divmod(other, self)."
|
|
6
|
+
|
|
7
|
+
[operator]
|
|
8
|
+
add = "+"
|
|
9
|
+
and_ = "&"
|
|
10
|
+
floordiv = "//"
|
|
11
|
+
lshift = "<<"
|
|
12
|
+
matmul = "@"
|
|
13
|
+
mod = "%"
|
|
14
|
+
mul = "*"
|
|
15
|
+
or_ = "|"
|
|
16
|
+
pow = "**"
|
|
17
|
+
rshift = ">>"
|
|
18
|
+
sub = "-"
|
|
19
|
+
truediv = "/"
|
|
20
|
+
xor = "^"
|
scaevola-1.0.16/src/scaevola/tests/test_0.py → scaevola-1.1.1/src/scaevola/tests/test_doc.py
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import unittest
|
|
2
|
+
from typing import *
|
|
2
3
|
|
|
3
4
|
from scaevola.core import Scaevola
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class TestScaevolaDocstrings(unittest.TestCase):
|
|
7
|
-
def test_methods_have_docstrings(self):
|
|
8
|
+
def test_methods_have_docstrings(self: Self) -> None:
|
|
8
9
|
methods_to_check = [
|
|
9
10
|
"__ge__",
|
|
10
11
|
"__gt__",
|
|
@@ -25,15 +26,11 @@ class TestScaevolaDocstrings(unittest.TestCase):
|
|
|
25
26
|
]
|
|
26
27
|
|
|
27
28
|
for name in methods_to_check:
|
|
28
|
-
method = getattr(Scaevola, name, None)
|
|
29
29
|
with self.subTest(method=name):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
len(method.__doc__.strip()),
|
|
35
|
-
0,
|
|
36
|
-
f"Method {name} has an empty docstring",
|
|
30
|
+
magic = getattr(Scaevola, name, None)
|
|
31
|
+
self.assertTrue(
|
|
32
|
+
magic.__doc__.startswith("This magic method "),
|
|
33
|
+
"doc=%r" % magic.__doc__,
|
|
37
34
|
)
|
|
38
35
|
|
|
39
36
|
|
|
@@ -17,10 +17,10 @@ class TestSlots(unittest.TestCase):
|
|
|
17
17
|
foo: Foo = Foo()
|
|
18
18
|
foo.x = 4
|
|
19
19
|
foo.y = 2
|
|
20
|
+
foo.z = 0
|
|
20
21
|
self.assertEqual(foo.x, 4)
|
|
21
22
|
self.assertEqual(foo.y, 2)
|
|
22
|
-
|
|
23
|
-
foo.z = 0
|
|
23
|
+
self.assertEqual(foo.z, 0)
|
|
24
24
|
|
|
25
25
|
def test_bar(self: Self) -> None:
|
|
26
26
|
bar: Bar = Bar()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from typing import *
|
|
3
|
+
|
|
4
|
+
from scaevola.core import auto
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@auto
|
|
8
|
+
class Foo:
|
|
9
|
+
__slots__ = ("x", "y")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@auto
|
|
13
|
+
class Bar:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestSlots(unittest.TestCase):
|
|
18
|
+
def test_foo(self: Self) -> None:
|
|
19
|
+
foo: Foo = Foo()
|
|
20
|
+
foo.x = 4
|
|
21
|
+
foo.y = 2
|
|
22
|
+
self.assertEqual(foo.x, 4)
|
|
23
|
+
self.assertEqual(foo.y, 2)
|
|
24
|
+
with self.assertRaises(AttributeError):
|
|
25
|
+
foo.z = 0
|
|
26
|
+
|
|
27
|
+
def test_bar(self: Self) -> None:
|
|
28
|
+
bar: Bar = Bar()
|
|
29
|
+
bar.x = 4
|
|
30
|
+
bar.y = 2
|
|
31
|
+
self.assertEqual(bar.x, 4)
|
|
32
|
+
self.assertEqual(bar.y, 2)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
unittest.main()
|
|
@@ -4,12 +4,14 @@ README.rst
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
setup.cfg
|
|
6
6
|
src/scaevola/__init__.py
|
|
7
|
-
src/scaevola/core.py
|
|
8
7
|
src/scaevola.egg-info/PKG-INFO
|
|
9
8
|
src/scaevola.egg-info/SOURCES.txt
|
|
10
9
|
src/scaevola.egg-info/dependency_links.txt
|
|
11
10
|
src/scaevola.egg-info/top_level.txt
|
|
11
|
+
src/scaevola/core/__init__.py
|
|
12
|
+
src/scaevola/core/cfg.toml
|
|
12
13
|
src/scaevola/tests/__init__.py
|
|
13
|
-
src/scaevola/tests/
|
|
14
|
+
src/scaevola/tests/test_doc.py
|
|
14
15
|
src/scaevola/tests/test_op.py
|
|
15
|
-
src/scaevola/tests/
|
|
16
|
+
src/scaevola/tests/test_slots_Scaevola.py
|
|
17
|
+
src/scaevola/tests/test_slots_auto.py
|
scaevola-1.0.16/MANIFEST.in
DELETED
|
File without changes
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
from typing import *
|
|
2
|
-
|
|
3
|
-
__all__ = ["Scaevola"]
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Scaevola:
|
|
7
|
-
|
|
8
|
-
__slots__ = ()
|
|
9
|
-
|
|
10
|
-
def __ge__(self: Self, other: Any) -> Any:
|
|
11
|
-
"This magic method implements self>=other."
|
|
12
|
-
return type(self)(other) <= self
|
|
13
|
-
|
|
14
|
-
def __gt__(self: Self, other: Any) -> Any:
|
|
15
|
-
"This magic method implements self>other."
|
|
16
|
-
return type(self)(other) < self
|
|
17
|
-
|
|
18
|
-
def __radd__(self: Self, other: Any) -> Any:
|
|
19
|
-
"This magic method implements other+self."
|
|
20
|
-
return type(self)(other) + self
|
|
21
|
-
|
|
22
|
-
def __rand__(self: Self, other: Any) -> Any:
|
|
23
|
-
"This magic method implements other&self."
|
|
24
|
-
return type(self)(other) & self
|
|
25
|
-
|
|
26
|
-
def __rdivmod__(self: Self, other: Any) -> Any:
|
|
27
|
-
"This magic method implements divmod(other, self)."
|
|
28
|
-
return divmod(type(self)(other), self)
|
|
29
|
-
|
|
30
|
-
def __rfloordiv__(self: Self, other: Any) -> Any:
|
|
31
|
-
"This magic method implements other//self."
|
|
32
|
-
return type(self)(other) // self
|
|
33
|
-
|
|
34
|
-
def __rlshift__(self: Self, other: Any) -> Any:
|
|
35
|
-
"This magic method implements other<<self."
|
|
36
|
-
return type(self)(other) << self
|
|
37
|
-
|
|
38
|
-
def __rmatmul__(self: Self, other: Any) -> Any:
|
|
39
|
-
"This magic method implements other@self."
|
|
40
|
-
return type(self)(other) @ self
|
|
41
|
-
|
|
42
|
-
def __rmod__(self: Self, other: Any) -> Any:
|
|
43
|
-
"This magic method implements other%self."
|
|
44
|
-
return type(self)(other) % self
|
|
45
|
-
|
|
46
|
-
def __rmul__(self: Self, other: Any) -> Any:
|
|
47
|
-
"This magic method implements other*self."
|
|
48
|
-
return type(self)(other) * self
|
|
49
|
-
|
|
50
|
-
def __ror__(self: Self, other: Any) -> Any:
|
|
51
|
-
"This magic method implements other|self."
|
|
52
|
-
return type(self)(other) | self
|
|
53
|
-
|
|
54
|
-
def __rpow__(self: Self, other: Any) -> Any:
|
|
55
|
-
"This magic method implements pow(other, self)."
|
|
56
|
-
return type(self)(other) ** self
|
|
57
|
-
|
|
58
|
-
def __rrshift__(self: Self, other: Any) -> Any:
|
|
59
|
-
"This magic method implements other>>self."
|
|
60
|
-
return type(self)(other) >> self
|
|
61
|
-
|
|
62
|
-
def __rsub__(self: Self, other: Any) -> Any:
|
|
63
|
-
"This magic method implements other-self."
|
|
64
|
-
return type(self)(other) - self
|
|
65
|
-
|
|
66
|
-
def __rtruediv__(self: Self, other: Any) -> Any:
|
|
67
|
-
"This magic method implements other/self."
|
|
68
|
-
return type(self)(other) / self
|
|
69
|
-
|
|
70
|
-
def __rxor__(self: Self, other: Any) -> Any:
|
|
71
|
-
"This magic method implements other^self."
|
|
72
|
-
return type(self)(other) ^ self
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|