Skip to content

Commit 45b3383

Browse files
cclaussgithub-actions
and
github-actions
authoredNov 2, 2022
Flake8: Drop ignore of issue A003 (#7949)
* Flake8: Drop ignore of issue A003 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 598f6a2 commit 45b3383

File tree

9 files changed

+42
-62
lines changed

9 files changed

+42
-62
lines changed
 

‎.flake8

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[flake8]
22
max-line-length = 88
3-
max-complexity = 25
3+
# max-complexity should be 10
4+
max-complexity = 23
45
extend-ignore =
5-
A003 # Class attribute is shadowing a python builtin
66
# Formatting style for `black`
77
E203 # Whitespace before ':'
88
W503 # Line break occurred before a binary operator

‎DIRECTORY.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* [Highest Set Bit](bit_manipulation/highest_set_bit.py)
4949
* [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py)
5050
* [Is Even](bit_manipulation/is_even.py)
51+
* [Is Power Of Two](bit_manipulation/is_power_of_two.py)
5152
* [Reverse Bits](bit_manipulation/reverse_bits.py)
5253
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
5354

@@ -315,6 +316,7 @@
315316
* [Minimum Partition](dynamic_programming/minimum_partition.py)
316317
* [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py)
317318
* [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py)
319+
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
318320
* [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py)
319321
* [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py)
320322
* [Rod Cutting](dynamic_programming/rod_cutting.py)
@@ -496,8 +498,6 @@
496498
## Maths
497499
* [3N Plus 1](maths/3n_plus_1.py)
498500
* [Abs](maths/abs.py)
499-
* [Abs Max](maths/abs_max.py)
500-
* [Abs Min](maths/abs_min.py)
501501
* [Add](maths/add.py)
502502
* [Addition Without Arithmetic](maths/addition_without_arithmetic.py)
503503
* [Aliquot Sum](maths/aliquot_sum.py)
@@ -653,6 +653,7 @@
653653
* [Matrix Operation](matrix/matrix_operation.py)
654654
* [Max Area Of Island](matrix/max_area_of_island.py)
655655
* [Nth Fibonacci Using Matrix Exponentiation](matrix/nth_fibonacci_using_matrix_exponentiation.py)
656+
* [Pascal Triangle](matrix/pascal_triangle.py)
656657
* [Rotate Matrix](matrix/rotate_matrix.py)
657658
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
658659
* [Sherman Morrison](matrix/sherman_morrison.py)
@@ -674,7 +675,6 @@
674675
## Other
675676
* [Activity Selection](other/activity_selection.py)
676677
* [Alternative List Arrange](other/alternative_list_arrange.py)
677-
* [Check Strong Password](other/check_strong_password.py)
678678
* [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py)
679679
* [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py)
680680
* [Doomsday](other/doomsday.py)
@@ -689,8 +689,7 @@
689689
* [Magicdiamondpattern](other/magicdiamondpattern.py)
690690
* [Maximum Subarray](other/maximum_subarray.py)
691691
* [Nested Brackets](other/nested_brackets.py)
692-
* [Pascal Triangle](other/pascal_triangle.py)
693-
* [Password Generator](other/password_generator.py)
692+
* [Password](other/password.py)
694693
* [Quine](other/quine.py)
695694
* [Scoring Algorithm](other/scoring_algorithm.py)
696695
* [Sdes](other/sdes.py)
@@ -701,6 +700,7 @@
701700
* [Casimir Effect](physics/casimir_effect.py)
702701
* [Centripetal Force](physics/centripetal_force.py)
703702
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
703+
* [Hubble Parameter](physics/hubble_parameter.py)
704704
* [Ideal Gas Law](physics/ideal_gas_law.py)
705705
* [Kinetic Energy](physics/kinetic_energy.py)
706706
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)

‎data_structures/binary_tree/fenwick_tree.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def init(self, arr: list[int]) -> None:
4646
self.size = len(arr)
4747
self.tree = deepcopy(arr)
4848
for i in range(1, self.size):
49-
j = self.next(i)
49+
j = self.next_(i)
5050
if j < self.size:
5151
self.tree[j] += self.tree[i]
5252

@@ -64,13 +64,13 @@ def get_array(self) -> list[int]:
6464
"""
6565
arr = self.tree[:]
6666
for i in range(self.size - 1, 0, -1):
67-
j = self.next(i)
67+
j = self.next_(i)
6868
if j < self.size:
6969
arr[j] -= arr[i]
7070
return arr
7171

7272
@staticmethod
73-
def next(index: int) -> int:
73+
def next_(index: int) -> int:
7474
return index + (index & (-index))
7575

7676
@staticmethod
@@ -102,7 +102,7 @@ def add(self, index: int, value: int) -> None:
102102
return
103103
while index < self.size:
104104
self.tree[index] += value
105-
index = self.next(index)
105+
index = self.next_(index)
106106

107107
def update(self, index: int, value: int) -> None:
108108
"""

‎data_structures/heap/heap.py

-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ def build_max_heap(self, collection: Iterable[float]) -> None:
8888
for i in range(self.heap_size // 2 - 1, -1, -1):
8989
self.max_heapify(i)
9090

91-
def max(self) -> float:
92-
"""return the max in the heap"""
93-
if self.heap_size >= 1:
94-
return self.h[0]
95-
else:
96-
raise Exception("Empty heap")
97-
9891
def extract_max(self) -> float:
9992
"""get and remove max from heap"""
10093
if self.heap_size >= 2:

‎data_structures/linked_list/merge_two_lists.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@dataclass
1414
class Node:
1515
data: int
16-
next: Node | None
16+
next_node: Node | None
1717

1818

1919
class SortedLinkedList:
@@ -32,7 +32,7 @@ def __iter__(self) -> Iterator[int]:
3232
node = self.head
3333
while node:
3434
yield node.data
35-
node = node.next
35+
node = node.next_node
3636

3737
def __len__(self) -> int:
3838
"""

‎data_structures/queue/double_ended_queue.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class _Node:
4242
"""
4343

4444
val: Any = None
45-
next: Deque._Node | None = None
46-
prev: Deque._Node | None = None
45+
next_node: Deque._Node | None = None
46+
prev_node: Deque._Node | None = None
4747

4848
class _Iterator:
4949
"""
@@ -81,7 +81,7 @@ def __next__(self) -> Any:
8181
# finished iterating
8282
raise StopIteration
8383
val = self._cur.val
84-
self._cur = self._cur.next
84+
self._cur = self._cur.next_node
8585

8686
return val
8787

@@ -128,8 +128,8 @@ def append(self, val: Any) -> None:
128128
self._len = 1
129129
else:
130130
# connect nodes
131-
self._back.next = node
132-
node.prev = self._back
131+
self._back.next_node = node
132+
node.prev_node = self._back
133133
self._back = node # assign new back to the new node
134134

135135
self._len += 1
@@ -170,8 +170,8 @@ def appendleft(self, val: Any) -> None:
170170
self._len = 1
171171
else:
172172
# connect nodes
173-
node.next = self._front
174-
self._front.prev = node
173+
node.next_node = self._front
174+
self._front.prev_node = node
175175
self._front = node # assign new front to the new node
176176

177177
self._len += 1
@@ -264,10 +264,9 @@ def pop(self) -> Any:
264264
assert not self.is_empty(), "Deque is empty."
265265

266266
topop = self._back
267-
self._back = self._back.prev # set new back
268-
self._back.next = (
269-
None # drop the last node - python will deallocate memory automatically
270-
)
267+
self._back = self._back.prev_node # set new back
268+
# drop the last node - python will deallocate memory automatically
269+
self._back.next_node = None
271270

272271
self._len -= 1
273272

@@ -300,8 +299,8 @@ def popleft(self) -> Any:
300299
assert not self.is_empty(), "Deque is empty."
301300

302301
topop = self._front
303-
self._front = self._front.next # set new front and drop the first node
304-
self._front.prev = None
302+
self._front = self._front.next_node # set new front and drop the first node
303+
self._front.prev_node = None
305304

306305
self._len -= 1
307306

@@ -385,8 +384,8 @@ def __eq__(self, other: object) -> bool:
385384
# compare every value
386385
if me.val != oth.val:
387386
return False
388-
me = me.next
389-
oth = oth.next
387+
me = me.next_node
388+
oth = oth.next_node
390389

391390
return True
392391

@@ -424,7 +423,7 @@ def __repr__(self) -> str:
424423
while aux is not None:
425424
# append the values in a list to display
426425
values_list.append(aux.val)
427-
aux = aux.next
426+
aux = aux.next_node
428427

429428
return "[" + ", ".join(repr(val) for val in values_list) + "]"
430429

‎linear_algebra/src/lib.py

-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Vector:
4040
__sub__(other: Vector): vector subtraction
4141
__mul__(other: float): scalar multiplication
4242
__mul__(other: Vector): dot product
43-
set(components: Collection[float]): changes the vector components
4443
copy(): copies this vector and returns it
4544
component(i): gets the i-th component (0-indexed)
4645
change_component(pos: int, value: float): changes specified component
@@ -119,17 +118,6 @@ def __mul__(self, other: float | Vector) -> float | Vector:
119118
else: # error case
120119
raise Exception("invalid operand!")
121120

122-
def set(self, components: Collection[float]) -> None:
123-
"""
124-
input: new components
125-
changes the components of the vector.
126-
replaces the components with newer one.
127-
"""
128-
if len(components) > 0:
129-
self.__components = list(components)
130-
else:
131-
raise Exception("please give any vector")
132-
133121
def copy(self) -> Vector:
134122
"""
135123
copies this vector and returns it.

‎other/lfu_cache.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ class LFUCache(Generic[T, U]):
166166
or as a function decorator.
167167
168168
>>> cache = LFUCache(2)
169-
>>> cache.set(1, 1)
170-
>>> cache.set(2, 2)
169+
>>> cache.put(1, 1)
170+
>>> cache.put(2, 2)
171171
>>> cache.get(1)
172172
1
173-
>>> cache.set(3, 3)
173+
>>> cache.put(3, 3)
174174
>>> cache.get(2) is None
175175
True
176-
>>> cache.set(4, 4)
176+
>>> cache.put(4, 4)
177177
>>> cache.get(1) is None
178178
True
179179
>>> cache.get(3)
@@ -224,7 +224,7 @@ def __contains__(self, key: T) -> bool:
224224
>>> 1 in cache
225225
False
226226
227-
>>> cache.set(1, 1)
227+
>>> cache.put(1, 1)
228228
>>> 1 in cache
229229
True
230230
"""
@@ -250,7 +250,7 @@ def get(self, key: T) -> U | None:
250250
self.miss += 1
251251
return None
252252

253-
def set(self, key: T, value: U) -> None:
253+
def put(self, key: T, value: U) -> None:
254254
"""
255255
Sets the value for the input key and updates the Double Linked List
256256
"""
@@ -297,7 +297,7 @@ def cache_decorator_wrapper(*args: T) -> U:
297297
result = cls.decorator_function_to_instance_map[func].get(args[0])
298298
if result is None:
299299
result = func(*args)
300-
cls.decorator_function_to_instance_map[func].set(args[0], result)
300+
cls.decorator_function_to_instance_map[func].put(args[0], result)
301301
return result
302302

303303
def cache_info() -> LFUCache[T, U]:

‎other/lru_cache.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ class LRUCache(Generic[T, U]):
150150
151151
>>> cache = LRUCache(2)
152152
153-
>>> cache.set(1, 1)
154-
>>> cache.set(2, 2)
153+
>>> cache.put(1, 1)
154+
>>> cache.put(2, 2)
155155
>>> cache.get(1)
156156
1
157157
@@ -166,7 +166,7 @@ class LRUCache(Generic[T, U]):
166166
{1: Node: key: 1, val: 1, has next: True, has prev: True, \
167167
2: Node: key: 2, val: 2, has next: True, has prev: True}
168168
169-
>>> cache.set(3, 3)
169+
>>> cache.put(3, 3)
170170
171171
>>> cache.list
172172
DoubleLinkedList,
@@ -182,7 +182,7 @@ class LRUCache(Generic[T, U]):
182182
>>> cache.get(2) is None
183183
True
184184
185-
>>> cache.set(4, 4)
185+
>>> cache.put(4, 4)
186186
187187
>>> cache.get(1) is None
188188
True
@@ -238,7 +238,7 @@ def __contains__(self, key: T) -> bool:
238238
>>> 1 in cache
239239
False
240240
241-
>>> cache.set(1, 1)
241+
>>> cache.put(1, 1)
242242
243243
>>> 1 in cache
244244
True
@@ -266,7 +266,7 @@ def get(self, key: T) -> U | None:
266266
self.miss += 1
267267
return None
268268

269-
def set(self, key: T, value: U) -> None:
269+
def put(self, key: T, value: U) -> None:
270270
"""
271271
Sets the value for the input key and updates the Double Linked List
272272
"""
@@ -315,7 +315,7 @@ def cache_decorator_wrapper(*args: T) -> U:
315315
result = cls.decorator_function_to_instance_map[func].get(args[0])
316316
if result is None:
317317
result = func(*args)
318-
cls.decorator_function_to_instance_map[func].set(args[0], result)
318+
cls.decorator_function_to_instance_map[func].put(args[0], result)
319319
return result
320320

321321
def cache_info() -> LRUCache[T, U]:

0 commit comments

Comments
 (0)
Please sign in to comment.