scaevola 1.0.15__tar.gz → 1.1.0__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.4
2
2
  Name: scaevola
3
- Version: 1.0.15
3
+ Version: 1.1.0
4
4
  Summary: This project provides a class with preset right handed magic methods.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -24,7 +24,7 @@ keywords = []
24
24
  name = "scaevola"
25
25
  readme = "README.rst"
26
26
  requires-python = ">=3.11"
27
- version = "1.0.15"
27
+ version = "1.1.0"
28
28
 
29
29
  [project.license]
30
30
  file = "LICENSE.txt"
@@ -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
@@ -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
- self.assertIsNotNone(
31
- method.__doc__, f"Method {name} is missing a docstring"
32
- )
33
- self.assertGreater(
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
 
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+ from typing import *
2
3
 
3
4
  from scaevola.core import Scaevola
4
5
 
@@ -0,0 +1,34 @@
1
+ import unittest
2
+ from typing import *
3
+
4
+ from scaevola.core import Scaevola
5
+
6
+
7
+ class Foo(Scaevola):
8
+ __slots__ = ("x", "y")
9
+
10
+
11
+ class Bar(Scaevola):
12
+ pass
13
+
14
+
15
+ class TestSlots(unittest.TestCase):
16
+ def test_foo(self: Self) -> None:
17
+ foo: Foo = Foo()
18
+ foo.x = 4
19
+ foo.y = 2
20
+ foo.z = 0
21
+ self.assertEqual(foo.x, 4)
22
+ self.assertEqual(foo.y, 2)
23
+ self.assertEqual(foo.z, 0)
24
+
25
+ def test_bar(self: Self) -> None:
26
+ bar: Bar = Bar()
27
+ bar.x = 4
28
+ bar.y = 2
29
+ self.assertEqual(bar.x, 4)
30
+ self.assertEqual(bar.y, 2)
31
+
32
+
33
+ if __name__ == "__main__":
34
+ unittest.main()
@@ -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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scaevola
3
- Version: 1.0.15
3
+ Version: 1.1.0
4
4
  Summary: This project provides a class with preset right handed magic methods.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License: The MIT License (MIT)
@@ -4,11 +4,13 @@ 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
12
  src/scaevola/tests/__init__.py
13
- src/scaevola/tests/test_0.py
14
- src/scaevola/tests/test_op.py
13
+ src/scaevola/tests/test_doc.py
14
+ src/scaevola/tests/test_op.py
15
+ src/scaevola/tests/test_slots_Scaevola.py
16
+ src/scaevola/tests/test_slots_auto.py
@@ -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