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>
This commit is contained in:
Christian Clauss 2022-11-02 19:20:45 +01:00 committed by GitHub
parent 598f6a26a1
commit 45b3383c39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 62 deletions

View File

@ -1,8 +1,8 @@
[flake8] [flake8]
max-line-length = 88 max-line-length = 88
max-complexity = 25 # max-complexity should be 10
max-complexity = 23
extend-ignore = extend-ignore =
A003 # Class attribute is shadowing a python builtin
# Formatting style for `black` # Formatting style for `black`
E203 # Whitespace before ':' E203 # Whitespace before ':'
W503 # Line break occurred before a binary operator W503 # Line break occurred before a binary operator

View File

@ -48,6 +48,7 @@
* [Highest Set Bit](bit_manipulation/highest_set_bit.py) * [Highest Set Bit](bit_manipulation/highest_set_bit.py)
* [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py) * [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py)
* [Is Even](bit_manipulation/is_even.py) * [Is Even](bit_manipulation/is_even.py)
* [Is Power Of Two](bit_manipulation/is_power_of_two.py)
* [Reverse Bits](bit_manipulation/reverse_bits.py) * [Reverse Bits](bit_manipulation/reverse_bits.py)
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py) * [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
@ -315,6 +316,7 @@
* [Minimum Partition](dynamic_programming/minimum_partition.py) * [Minimum Partition](dynamic_programming/minimum_partition.py)
* [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py) * [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py)
* [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py) * [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py)
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
* [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py) * [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py)
* [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py) * [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py)
* [Rod Cutting](dynamic_programming/rod_cutting.py) * [Rod Cutting](dynamic_programming/rod_cutting.py)
@ -496,8 +498,6 @@
## Maths ## Maths
* [3N Plus 1](maths/3n_plus_1.py) * [3N Plus 1](maths/3n_plus_1.py)
* [Abs](maths/abs.py) * [Abs](maths/abs.py)
* [Abs Max](maths/abs_max.py)
* [Abs Min](maths/abs_min.py)
* [Add](maths/add.py) * [Add](maths/add.py)
* [Addition Without Arithmetic](maths/addition_without_arithmetic.py) * [Addition Without Arithmetic](maths/addition_without_arithmetic.py)
* [Aliquot Sum](maths/aliquot_sum.py) * [Aliquot Sum](maths/aliquot_sum.py)
@ -653,6 +653,7 @@
* [Matrix Operation](matrix/matrix_operation.py) * [Matrix Operation](matrix/matrix_operation.py)
* [Max Area Of Island](matrix/max_area_of_island.py) * [Max Area Of Island](matrix/max_area_of_island.py)
* [Nth Fibonacci Using Matrix Exponentiation](matrix/nth_fibonacci_using_matrix_exponentiation.py) * [Nth Fibonacci Using Matrix Exponentiation](matrix/nth_fibonacci_using_matrix_exponentiation.py)
* [Pascal Triangle](matrix/pascal_triangle.py)
* [Rotate Matrix](matrix/rotate_matrix.py) * [Rotate Matrix](matrix/rotate_matrix.py)
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py) * [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
* [Sherman Morrison](matrix/sherman_morrison.py) * [Sherman Morrison](matrix/sherman_morrison.py)
@ -674,7 +675,6 @@
## Other ## Other
* [Activity Selection](other/activity_selection.py) * [Activity Selection](other/activity_selection.py)
* [Alternative List Arrange](other/alternative_list_arrange.py) * [Alternative List Arrange](other/alternative_list_arrange.py)
* [Check Strong Password](other/check_strong_password.py)
* [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py) * [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py)
* [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py) * [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py)
* [Doomsday](other/doomsday.py) * [Doomsday](other/doomsday.py)
@ -689,8 +689,7 @@
* [Magicdiamondpattern](other/magicdiamondpattern.py) * [Magicdiamondpattern](other/magicdiamondpattern.py)
* [Maximum Subarray](other/maximum_subarray.py) * [Maximum Subarray](other/maximum_subarray.py)
* [Nested Brackets](other/nested_brackets.py) * [Nested Brackets](other/nested_brackets.py)
* [Pascal Triangle](other/pascal_triangle.py) * [Password](other/password.py)
* [Password Generator](other/password_generator.py)
* [Quine](other/quine.py) * [Quine](other/quine.py)
* [Scoring Algorithm](other/scoring_algorithm.py) * [Scoring Algorithm](other/scoring_algorithm.py)
* [Sdes](other/sdes.py) * [Sdes](other/sdes.py)
@ -701,6 +700,7 @@
* [Casimir Effect](physics/casimir_effect.py) * [Casimir Effect](physics/casimir_effect.py)
* [Centripetal Force](physics/centripetal_force.py) * [Centripetal Force](physics/centripetal_force.py)
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
* [Hubble Parameter](physics/hubble_parameter.py)
* [Ideal Gas Law](physics/ideal_gas_law.py) * [Ideal Gas Law](physics/ideal_gas_law.py)
* [Kinetic Energy](physics/kinetic_energy.py) * [Kinetic Energy](physics/kinetic_energy.py)
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)

View File

@ -46,7 +46,7 @@ class FenwickTree:
self.size = len(arr) self.size = len(arr)
self.tree = deepcopy(arr) self.tree = deepcopy(arr)
for i in range(1, self.size): for i in range(1, self.size):
j = self.next(i) j = self.next_(i)
if j < self.size: if j < self.size:
self.tree[j] += self.tree[i] self.tree[j] += self.tree[i]
@ -64,13 +64,13 @@ class FenwickTree:
""" """
arr = self.tree[:] arr = self.tree[:]
for i in range(self.size - 1, 0, -1): for i in range(self.size - 1, 0, -1):
j = self.next(i) j = self.next_(i)
if j < self.size: if j < self.size:
arr[j] -= arr[i] arr[j] -= arr[i]
return arr return arr
@staticmethod @staticmethod
def next(index: int) -> int: def next_(index: int) -> int:
return index + (index & (-index)) return index + (index & (-index))
@staticmethod @staticmethod
@ -102,7 +102,7 @@ class FenwickTree:
return return
while index < self.size: while index < self.size:
self.tree[index] += value self.tree[index] += value
index = self.next(index) index = self.next_(index)
def update(self, index: int, value: int) -> None: def update(self, index: int, value: int) -> None:
""" """

View File

@ -88,13 +88,6 @@ class Heap:
for i in range(self.heap_size // 2 - 1, -1, -1): for i in range(self.heap_size // 2 - 1, -1, -1):
self.max_heapify(i) self.max_heapify(i)
def max(self) -> float:
"""return the max in the heap"""
if self.heap_size >= 1:
return self.h[0]
else:
raise Exception("Empty heap")
def extract_max(self) -> float: def extract_max(self) -> float:
"""get and remove max from heap""" """get and remove max from heap"""
if self.heap_size >= 2: if self.heap_size >= 2:

View File

@ -13,7 +13,7 @@ test_data_even = (4, 6, 2, 0, 8, 10, 3, -2)
@dataclass @dataclass
class Node: class Node:
data: int data: int
next: Node | None next_node: Node | None
class SortedLinkedList: class SortedLinkedList:
@ -32,7 +32,7 @@ class SortedLinkedList:
node = self.head node = self.head
while node: while node:
yield node.data yield node.data
node = node.next node = node.next_node
def __len__(self) -> int: def __len__(self) -> int:
""" """

View File

@ -42,8 +42,8 @@ class Deque:
""" """
val: Any = None val: Any = None
next: Deque._Node | None = None next_node: Deque._Node | None = None
prev: Deque._Node | None = None prev_node: Deque._Node | None = None
class _Iterator: class _Iterator:
""" """
@ -81,7 +81,7 @@ class Deque:
# finished iterating # finished iterating
raise StopIteration raise StopIteration
val = self._cur.val val = self._cur.val
self._cur = self._cur.next self._cur = self._cur.next_node
return val return val
@ -128,8 +128,8 @@ class Deque:
self._len = 1 self._len = 1
else: else:
# connect nodes # connect nodes
self._back.next = node self._back.next_node = node
node.prev = self._back node.prev_node = self._back
self._back = node # assign new back to the new node self._back = node # assign new back to the new node
self._len += 1 self._len += 1
@ -170,8 +170,8 @@ class Deque:
self._len = 1 self._len = 1
else: else:
# connect nodes # connect nodes
node.next = self._front node.next_node = self._front
self._front.prev = node self._front.prev_node = node
self._front = node # assign new front to the new node self._front = node # assign new front to the new node
self._len += 1 self._len += 1
@ -264,10 +264,9 @@ class Deque:
assert not self.is_empty(), "Deque is empty." assert not self.is_empty(), "Deque is empty."
topop = self._back topop = self._back
self._back = self._back.prev # set new back self._back = self._back.prev_node # set new back
self._back.next = ( # drop the last node - python will deallocate memory automatically
None # drop the last node - python will deallocate memory automatically self._back.next_node = None
)
self._len -= 1 self._len -= 1
@ -300,8 +299,8 @@ class Deque:
assert not self.is_empty(), "Deque is empty." assert not self.is_empty(), "Deque is empty."
topop = self._front topop = self._front
self._front = self._front.next # set new front and drop the first node self._front = self._front.next_node # set new front and drop the first node
self._front.prev = None self._front.prev_node = None
self._len -= 1 self._len -= 1
@ -385,8 +384,8 @@ class Deque:
# compare every value # compare every value
if me.val != oth.val: if me.val != oth.val:
return False return False
me = me.next me = me.next_node
oth = oth.next oth = oth.next_node
return True return True
@ -424,7 +423,7 @@ class Deque:
while aux is not None: while aux is not None:
# append the values in a list to display # append the values in a list to display
values_list.append(aux.val) values_list.append(aux.val)
aux = aux.next aux = aux.next_node
return "[" + ", ".join(repr(val) for val in values_list) + "]" return "[" + ", ".join(repr(val) for val in values_list) + "]"

View File

@ -40,7 +40,6 @@ class Vector:
__sub__(other: Vector): vector subtraction __sub__(other: Vector): vector subtraction
__mul__(other: float): scalar multiplication __mul__(other: float): scalar multiplication
__mul__(other: Vector): dot product __mul__(other: Vector): dot product
set(components: Collection[float]): changes the vector components
copy(): copies this vector and returns it copy(): copies this vector and returns it
component(i): gets the i-th component (0-indexed) component(i): gets the i-th component (0-indexed)
change_component(pos: int, value: float): changes specified component change_component(pos: int, value: float): changes specified component
@ -119,17 +118,6 @@ class Vector:
else: # error case else: # error case
raise Exception("invalid operand!") raise Exception("invalid operand!")
def set(self, components: Collection[float]) -> None:
"""
input: new components
changes the components of the vector.
replaces the components with newer one.
"""
if len(components) > 0:
self.__components = list(components)
else:
raise Exception("please give any vector")
def copy(self) -> Vector: def copy(self) -> Vector:
""" """
copies this vector and returns it. copies this vector and returns it.

View File

@ -166,14 +166,14 @@ class LFUCache(Generic[T, U]):
or as a function decorator. or as a function decorator.
>>> cache = LFUCache(2) >>> cache = LFUCache(2)
>>> cache.set(1, 1) >>> cache.put(1, 1)
>>> cache.set(2, 2) >>> cache.put(2, 2)
>>> cache.get(1) >>> cache.get(1)
1 1
>>> cache.set(3, 3) >>> cache.put(3, 3)
>>> cache.get(2) is None >>> cache.get(2) is None
True True
>>> cache.set(4, 4) >>> cache.put(4, 4)
>>> cache.get(1) is None >>> cache.get(1) is None
True True
>>> cache.get(3) >>> cache.get(3)
@ -224,7 +224,7 @@ class LFUCache(Generic[T, U]):
>>> 1 in cache >>> 1 in cache
False False
>>> cache.set(1, 1) >>> cache.put(1, 1)
>>> 1 in cache >>> 1 in cache
True True
""" """
@ -250,7 +250,7 @@ class LFUCache(Generic[T, U]):
self.miss += 1 self.miss += 1
return None return None
def set(self, key: T, value: U) -> None: def put(self, key: T, value: U) -> None:
""" """
Sets the value for the input key and updates the Double Linked List Sets the value for the input key and updates the Double Linked List
""" """
@ -297,7 +297,7 @@ class LFUCache(Generic[T, U]):
result = cls.decorator_function_to_instance_map[func].get(args[0]) result = cls.decorator_function_to_instance_map[func].get(args[0])
if result is None: if result is None:
result = func(*args) result = func(*args)
cls.decorator_function_to_instance_map[func].set(args[0], result) cls.decorator_function_to_instance_map[func].put(args[0], result)
return result return result
def cache_info() -> LFUCache[T, U]: def cache_info() -> LFUCache[T, U]:

View File

@ -150,8 +150,8 @@ class LRUCache(Generic[T, U]):
>>> cache = LRUCache(2) >>> cache = LRUCache(2)
>>> cache.set(1, 1) >>> cache.put(1, 1)
>>> cache.set(2, 2) >>> cache.put(2, 2)
>>> cache.get(1) >>> cache.get(1)
1 1
@ -166,7 +166,7 @@ class LRUCache(Generic[T, U]):
{1: Node: key: 1, val: 1, has next: True, has prev: True, \ {1: Node: key: 1, val: 1, has next: True, has prev: True, \
2: Node: key: 2, val: 2, has next: True, has prev: True} 2: Node: key: 2, val: 2, has next: True, has prev: True}
>>> cache.set(3, 3) >>> cache.put(3, 3)
>>> cache.list >>> cache.list
DoubleLinkedList, DoubleLinkedList,
@ -182,7 +182,7 @@ class LRUCache(Generic[T, U]):
>>> cache.get(2) is None >>> cache.get(2) is None
True True
>>> cache.set(4, 4) >>> cache.put(4, 4)
>>> cache.get(1) is None >>> cache.get(1) is None
True True
@ -238,7 +238,7 @@ class LRUCache(Generic[T, U]):
>>> 1 in cache >>> 1 in cache
False False
>>> cache.set(1, 1) >>> cache.put(1, 1)
>>> 1 in cache >>> 1 in cache
True True
@ -266,7 +266,7 @@ class LRUCache(Generic[T, U]):
self.miss += 1 self.miss += 1
return None return None
def set(self, key: T, value: U) -> None: def put(self, key: T, value: U) -> None:
""" """
Sets the value for the input key and updates the Double Linked List Sets the value for the input key and updates the Double Linked List
""" """
@ -315,7 +315,7 @@ class LRUCache(Generic[T, U]):
result = cls.decorator_function_to_instance_map[func].get(args[0]) result = cls.decorator_function_to_instance_map[func].get(args[0])
if result is None: if result is None:
result = func(*args) result = func(*args)
cls.decorator_function_to_instance_map[func].set(args[0], result) cls.decorator_function_to_instance_map[func].put(args[0], result)
return result return result
def cache_info() -> LRUCache[T, U]: def cache_info() -> LRUCache[T, U]: