mywheel 0.2__py3-none-any.whl

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.
mywheel/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ import sys
2
+ from importlib.metadata import PackageNotFoundError, version
3
+
4
+ try:
5
+ # Change here if project is renamed and does not equal the package name
6
+ dist_name = __name__
7
+ __version__ = version(dist_name)
8
+ except PackageNotFoundError: # pragma: no cover
9
+ __version__ = "unknown"
10
+ finally:
11
+ del version, PackageNotFoundError
mywheel/array_like.py ADDED
@@ -0,0 +1,268 @@
1
+ from itertools import repeat
2
+
3
+
4
+ class RepeatArray:
5
+ """The RepeatArray class creates a list-like object that repeats a given value for a specified number
6
+ of times."""
7
+
8
+ def __init__(self, value, size):
9
+ """
10
+ The function initializes an object with a value and size attribute.
11
+
12
+ :param value: The value parameter is used to store the value of an object. It can be of any data type, such as an integer, string, or even another object
13
+ :param size: The `size` parameter represents the size of an object or data structure.
14
+
15
+ Examples:
16
+ >>> repeat_array = RepeatArray(1, 5)
17
+ >>> repeat_array.value
18
+ 1
19
+ >>> repeat_array.size
20
+ 5
21
+
22
+ """
23
+ self.value = value
24
+ self.size = size
25
+
26
+ def __getitem__(self, _): # key is ignored
27
+ """
28
+ The `__getitem__` function returns the value of the object regardless of the key provided.
29
+
30
+ :param _: The parameter "_" in the __getitem__ method is used to indicate that the key argument is
31
+ ignored. It is a convention in Python to use "_" as a placeholder for variables that are not used or
32
+ not important in a particular context. In this case, the key argument is not used in the method implementation
33
+
34
+ :return: The value stored in the `self.value` attribute.
35
+
36
+ Examples:
37
+ >>> repeat_array = RepeatArray(1, 5)
38
+ >>> repeat_array[0]
39
+ 1
40
+ >>> repeat_array[1]
41
+ 1
42
+ >>> repeat_array[2]
43
+ 1
44
+ >>> repeat_array[3]
45
+ 1
46
+ >>> repeat_array[4]
47
+ 1
48
+
49
+ """
50
+ return self.value
51
+
52
+ def __len__(self):
53
+ """
54
+ The function returns the size of an object.
55
+
56
+ :return: The size of the object.
57
+
58
+ Examples:
59
+ >>> repeat_array = RepeatArray(1, 5)
60
+ >>> len(repeat_array)
61
+ 5
62
+
63
+ """
64
+ return self.size
65
+
66
+ def __iter__(self):
67
+ """
68
+ The function returns an iterator that repeats the value of the object a specified number of times.
69
+
70
+ :return: The `repeat` function is being returned.
71
+
72
+ Examples:
73
+ >>> repeat_array = RepeatArray(1, 5)
74
+ >>> for i in repeat_array:
75
+ ... print(i)
76
+ 1
77
+ 1
78
+ 1
79
+ 1
80
+ 1
81
+ """
82
+ return repeat(self.value, self.size)
83
+
84
+ def get(self, _): # defaultvalue is ignored
85
+ """
86
+ The `get` function returns the value of the object.
87
+
88
+ :param _: The underscore (_) is a convention in Python to indicate that a parameter is not going to
89
+ be used in the function. In this case, the parameter is ignored and not used in the function logic
90
+
91
+ :return: The value of the `self.value` attribute is being returned.
92
+
93
+ Examples:
94
+ >>> repeat_array = RepeatArray(1, 5)
95
+ >>> repeat_array.get(0)
96
+ 1
97
+ >>> repeat_array.get(1)
98
+ 1
99
+ >>> repeat_array.get(2)
100
+ 1
101
+ >>> repeat_array.get(3)
102
+ 1
103
+ >>> repeat_array.get(4)
104
+ 1
105
+
106
+ """
107
+ return self.value
108
+
109
+
110
+ # The ShiftArray class is a subclass of the list class that allows for indexing and setting values
111
+ # with an arbitrary starting index.
112
+ class ShiftArray(list):
113
+ """ShiftArray
114
+ The `ShiftArray` class is a subclass of the built-in `list` class in Python. It extends the
115
+ functionality of a list by allowing the user to set a starting index for the list.
116
+ list with arbitrary range
117
+ """
118
+
119
+ def __new__(cls, *args, **kwargs):
120
+ """
121
+ The function overrides the `__new__` method of the `list` class in Python.
122
+
123
+ :param cls: The `cls` parameter in the `__new__` method refers to the class itself. It is automatically passed as the first argument when the method is called
124
+
125
+ :return: The `__new__` method is returning a new instance of the class `cls` as a list.
126
+
127
+ Examples:
128
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
129
+ >>> shift_array.set_start(3)
130
+ >>> shift_array[6]
131
+ 4
132
+ >>> shift_array[7]
133
+ 5
134
+ >>> shift_array[3]
135
+ 1
136
+ >>> shift_array[4]
137
+ 2
138
+ >>> shift_array[5]
139
+ 3
140
+ """
141
+ return list.__new__(cls, *args, **kwargs)
142
+
143
+ def __init__(self, *args, **kwargs):
144
+ """
145
+ The function is a constructor that initializes an object with a start value of 0 and calls the
146
+ constructor of the parent class "list".
147
+
148
+ Examples:
149
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
150
+ >>> shift_array.set_start(3)
151
+ >>> shift_array[6]
152
+ 4
153
+ >>> shift_array[7]
154
+ 5
155
+ >>> shift_array[3]
156
+ 1
157
+ >>> shift_array[4]
158
+ 2
159
+ >>> shift_array[5]
160
+ 3
161
+ """
162
+ self.start = 0
163
+ list.__init__(self, *args, **kwargs)
164
+
165
+ def set_start(self, start):
166
+ """
167
+ The function sets the value of the "start" attribute.
168
+
169
+ :param start: The `start` parameter is a value that will be assigned to the `start` attribute of the object
170
+
171
+ Examples:
172
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
173
+ >>> shift_array.set_start(3)
174
+ >>> shift_array[6]
175
+ 4
176
+ >>> shift_array[7]
177
+ 5
178
+ >>> shift_array[3]
179
+ 1
180
+ >>> shift_array[4]
181
+ 2
182
+ >>> shift_array[5]
183
+ 3
184
+ """
185
+ self.start = start
186
+
187
+ def __len__(self):
188
+ return list.__len__(self)
189
+
190
+ def __getitem__(self, key):
191
+ """
192
+ The `__getitem__` function returns the item at the specified index, adjusted by the `start` attribute.
193
+
194
+ :param key: The `key` parameter is the index or slice object used to access the elements of the list. It can be an integer index or a slice object that specifies a range of indices
195
+ :return: The method is returning the item at the specified index in the list.
196
+
197
+ Examples:
198
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
199
+ >>> shift_array.set_start(3)
200
+ >>> shift_array[6]
201
+ 4
202
+ >>> shift_array[7]
203
+ 5
204
+ >>> shift_array[3]
205
+ 1
206
+ >>> shift_array[4]
207
+ 2
208
+ >>> shift_array[5]
209
+ 3
210
+
211
+ """
212
+ if not (0 <= key - self.start < len(self)):
213
+ raise IndexError("Index out of range")
214
+ return list.__getitem__(self, key - self.start)
215
+
216
+ def __setitem__(self, key, newValue):
217
+ """
218
+ The `__setitem__` function is used to set the value of an item in a list-like object, adjusting the
219
+ index based on the start value.
220
+
221
+ :param key: The key parameter represents the index of the element in the list that you want to set a new value for
222
+ :param newValue: The `newValue` parameter is the value that you want to set for the given key in the list
223
+
224
+ Examples:
225
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
226
+ >>> shift_array.set_start(3)
227
+ >>> shift_array[6]
228
+ 4
229
+ >>> shift_array[6] = 8
230
+ >>> shift_array[6]
231
+ 8
232
+ """
233
+ list.__setitem__(self, key - self.start, newValue)
234
+
235
+ def items(self):
236
+ """
237
+ The `items` function returns an iterator that yields tuples containing the index and value of each
238
+ element in the object.
239
+
240
+ :return: The `items` method is returning an iterator that yields tuples containing the index (starting from `self.start`) and the corresponding value for each element in the object.
241
+
242
+ Examples:
243
+ >>> shift_array = ShiftArray([1, 2, 3, 4, 5])
244
+ >>> shift_array.set_start(3)
245
+ >>> for i, v in shift_array.items():
246
+ ... print(i, v)
247
+ 3 1
248
+ 4 2
249
+ 5 3
250
+ 6 4
251
+ 7 5
252
+
253
+ """
254
+ return iter((i + self.start, v) for i, v in enumerate(self))
255
+
256
+
257
+ # The main function is used to test the classes
258
+ if __name__ == "__main__":
259
+ arr = RepeatArray(1, 10)
260
+ print(arr[4])
261
+ for i in arr:
262
+ print(i)
263
+
264
+ b = ShiftArray([9, 4, 1, 3, 8, 7, 6, 5])
265
+ b.set_start(10)
266
+ print(b[14])
267
+ for i in b:
268
+ print(i)