kbasic 0.2.3__tar.gz → 0.3.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.
Files changed (27) hide show
  1. {kbasic-0.2.3 → kbasic-0.3.1}/PKG-INFO +1 -1
  2. {kbasic-0.2.3 → kbasic-0.3.1}/pyproject.toml +1 -1
  3. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/__init__.py +1 -1
  4. kbasic-0.3.1/src/kbasic/typing.py +34 -0
  5. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/vectors.py +17 -17
  6. kbasic-0.2.3/src/kbasic/typing.py +0 -34
  7. {kbasic-0.2.3 → kbasic-0.3.1}/README.md +0 -0
  8. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/Tex.py +0 -0
  9. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/array.py +0 -0
  10. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/audio/__init__.py +0 -0
  11. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/audio/lib/Caroline Rose - year of the slug - 01 everything in its right place.wav +0 -0
  12. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/audio/lib/success.mp3 +0 -0
  13. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/audio/sound.py +0 -0
  14. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/bar.py +0 -0
  15. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/environment/Keyan.py +0 -0
  16. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/environment/__init__.py +0 -0
  17. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/environment/anvil.py +0 -0
  18. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/environment/defaultPC.py +0 -0
  19. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/__init__.py +0 -0
  20. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/basic.py +0 -0
  21. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/log.py +0 -0
  22. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/parser.py +0 -0
  23. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/toml.py +0 -0
  24. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/parsing/utils.py +0 -0
  25. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/shell.py +0 -0
  26. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/strings.py +0 -0
  27. {kbasic-0.2.3 → kbasic-0.3.1}/src/kbasic/user_input.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: kbasic
3
- Version: 0.2.3
3
+ Version: 0.3.1
4
4
  Summary: Keyan's basic utility functions.
5
5
  Author: Keyan Gootkin
6
6
  Author-email: Keyan Gootkin <keyangootkin@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kbasic"
3
- version = "0.2.3"
3
+ version = "0.3.1"
4
4
  description = "Keyan's basic utility functions."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -8,4 +8,4 @@ from kbasic.user_input import *
8
8
  from kbasic.Tex import *
9
9
  from kbasic.typing import *
10
10
  from kbasic.vectors import *
11
- from kbasic.parsing import *
11
+ from kbasic.parsing import *
@@ -0,0 +1,34 @@
1
+ """
2
+ Use ABCs to allow matching any number or array type, e.g. this will work:
3
+ match 1.:
4
+ case Number(): ...
5
+
6
+ or:
7
+ match {1, 2, 3, 4}:
8
+ case Array(): ...
9
+ """
10
+ # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
11
+ # >-|===|> Imports <|===|-<
12
+ # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
13
+ from abc import ABC
14
+ from collections.abc import Generator
15
+ from numpy import int8, uint8, int16, uint16, int32, uint32, int64, uint64, \
16
+ float16, float32, float64, longdouble, complex64, complex128, \
17
+ clongdouble, ndarray
18
+ # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
19
+ # >-|===|> Types <|===|-<
20
+ # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
21
+ class Array(ABC):
22
+ types: list = [ndarray, list, set, tuple, Generator]
23
+ @classmethod
24
+ def __subclasshook__(cls, sub):
25
+ return sub in cls.types
26
+ class Number(ABC):
27
+ types: list = [
28
+ int, int8, uint8, int16, uint16, int32, uint32, int64, uint64,
29
+ float, float16, float32, float64, longdouble,
30
+ complex, complex64, complex128, clongdouble
31
+ ]
32
+ @classmethod
33
+ def __subclasshook__(cls, sub):
34
+ return sub in cls.types
@@ -28,9 +28,9 @@ def hamilton_product(q1, q2):
28
28
  class VectorBase:
29
29
  def __init__(self, *components) -> None:
30
30
  match components[0]:
31
- case x if type(x) in Number.types:
31
+ case Number():
32
32
  self.components = components
33
- case x if type(x) in Array.types:
33
+ case Array():
34
34
  self.components = tuple(array(x) for x in components)
35
35
  case Generator():
36
36
  self.components = tuple(components[0])
@@ -77,15 +77,15 @@ class VectorBase:
77
77
  match other:
78
78
  case VectorBase():
79
79
  return Vector(xs+xo for xs, xo in zip(self.components, other.components))
80
- case x if type(x) in Number.types:
80
+ case Number():
81
81
  return Vector(xi+other for xi in self)
82
- case x if type(x) in Array.types:
82
+ case Array():
83
83
  return Vector(xs+xo for xs, xo in zip(self.components, other))
84
84
  def __sub__(self, other) -> Self:
85
85
  match other:
86
- case x if type(x) in Number.types:
86
+ case Number():
87
87
  return type(self)(x-other for x in self)
88
- case x if type(x) in Array.types:
88
+ case Array():
89
89
  return type(self)(xs-xo for xs, xo in zip(self.components, other))
90
90
  case VectorBase():
91
91
  return type(self)(xs-xo for xs, xo in zip(self.components, other.components))
@@ -93,23 +93,23 @@ class VectorBase:
93
93
  match other:
94
94
  case VectorBase():
95
95
  return sum(list(c1*c2 for c1,c2 in zip(self, other)), axis=0)
96
- case x if type(x) in Number.types:
96
+ case Number():
97
97
  return type(self)(c*other for c in self)
98
- case x if type(x) in Array.types:
98
+ case Array():
99
99
  return type(self)(c1*c2 for c1, c2 in zip(self, other))
100
100
  def __truediv__(self, other) -> Self:
101
101
  match other:
102
102
  case VectorBase():
103
103
  return Vector(c1 / c2 for c1, c2 in zip(self, other))
104
- case x if type(x) in Number.types:
104
+ case Number():
105
105
  return type(self)(c / other for c in self)
106
- case x if type(x) in Array.types:
106
+ case Array():
107
107
  return type(self)(c1 / c2 for c1, c2 in zip(self, other))
108
108
  def __floordiv__(self, other) -> Self:
109
109
  match other:
110
- case x if type(x) in Number.types:
110
+ case Number():
111
111
  return type(self)(c//other for c in self)
112
- case x if type(x) in Array.types:
112
+ case Array():
113
113
  return type(self)(c1//c2 for c1, c2 in zip(self, other))
114
114
  def __radd__(self, other) -> Self:
115
115
  match other:
@@ -125,15 +125,15 @@ class VectorBase:
125
125
  case _: return self.__mul__(other)
126
126
  def __rtruediv__(self, other) -> Self:
127
127
  match other:
128
- case x if type(x) in Number.types:
128
+ case Number():
129
129
  return type(self)(other/c for c in self)
130
- case x if type(x) in Array.types:
130
+ case Array():
131
131
  return type(self)(c2/c1 for c1, c2 in zip(self, other))
132
132
  def __rfloordiv__(self, other) -> Self:
133
133
  match other:
134
- case x if type(x) in Number.types:
134
+ case Number():
135
135
  return type(self)(other//c for c in self)
136
- case x if type(x) in Array.types:
136
+ case Array():
137
137
  return type(self)(c2//c1 for c1, c2 in zip(self, other))
138
138
  class Vector(VectorBase):
139
139
  def __new__(cls, *components) -> Self: # the vector factory
@@ -145,7 +145,7 @@ class Vector(VectorBase):
145
145
  case (Generator(),):
146
146
  return Vector(tuple(components[0]))
147
147
  # single array
148
- case (x,) if type(x) in Array.types:
148
+ case (Array(),):
149
149
  return Vector(*x)
150
150
  # 2D
151
151
  case (x, y):
@@ -1,34 +0,0 @@
1
- """
2
- I don't like type checking in python, so the way i decided to do it is if i want
3
- to see if something looks like a number (int, float, complex or numpy variants)
4
- i would say ->
5
- if type(x) in Number.types: do_something()
6
- elif type(x) in Array.types: do_something_else()
7
- """
8
- # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
9
- # >-|===|> Imports <|===|-<
10
- # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
11
- from numpy import int8, uint8, int16, uint16, int32, uint32, int64, uint64, \
12
- float16, float32, float64, longdouble, complex64, complex128, \
13
- clongdouble, ndarray
14
- from numpy.typing import NDArray, ArrayLike
15
- from collections.abc import Callable, Generator
16
- from typing import Any
17
- # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
18
- # >-|===|> Types <|===|-<
19
- # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
20
- class Array:
21
- types: list = [NDArray, ndarray, list, set, tuple, Generator]
22
- class Number:
23
- types: list = [
24
- int, int8, uint8, int16, uint16, int32, uint32, int64, uint64,
25
- float, float16, float32, float64, longdouble,
26
- complex, complex64, complex128, clongdouble
27
- ]
28
- def __new__(cls, x):
29
- match x:
30
- case x if type(x) in Number.types: return x
31
- case str() if x.isnumeric(): return int(x)
32
- case str() if '.' in x and all([xi.isnumeric() for xi in x.split('.')]):
33
- return float(x)
34
- case _: raise ValueError(f"Cannot parse argument: {x}\nof type: {type(x)}")
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