mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Enable ruff PGH003 rule (#11345)
* Enable ruff PGH003 rule * Fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f5bbea3776
commit
53b2926704
|
@ -40,7 +40,7 @@ def build_tree(letters: list[Letter]) -> Letter | TreeNode:
|
|||
Run through the list of Letters and build the min heap
|
||||
for the Huffman Tree.
|
||||
"""
|
||||
response: list[Letter | TreeNode] = letters # type: ignore
|
||||
response: list[Letter | TreeNode] = list(letters)
|
||||
while len(response) > 1:
|
||||
left = response.pop(0)
|
||||
right = response.pop(0)
|
||||
|
@ -59,7 +59,7 @@ def traverse_tree(root: Letter | TreeNode, bitstring: str) -> list[Letter]:
|
|||
if isinstance(root, Letter):
|
||||
root.bitstring[root.letter] = bitstring
|
||||
return [root]
|
||||
treenode: TreeNode = root # type: ignore
|
||||
treenode: TreeNode = root
|
||||
letters = []
|
||||
letters += traverse_tree(treenode.left, bitstring + "0")
|
||||
letters += traverse_tree(treenode.right, bitstring + "1")
|
||||
|
|
|
@ -294,9 +294,9 @@ class BinarySearchTree:
|
|||
predecessor = self.get_max(
|
||||
node.left
|
||||
) # Gets the max value of the left branch
|
||||
self.remove(predecessor.value) # type: ignore
|
||||
self.remove(predecessor.value) # type: ignore[union-attr]
|
||||
node.value = (
|
||||
predecessor.value # type: ignore
|
||||
predecessor.value # type: ignore[union-attr]
|
||||
) # Assigns the value to the node to delete and keep tree structure
|
||||
|
||||
def preorder_traverse(self, node: Node | None) -> Iterable:
|
||||
|
|
|
@ -63,7 +63,7 @@ def insert_node(head: Node | None, data: int) -> Node:
|
|||
while temp_node.next_node:
|
||||
temp_node = temp_node.next_node
|
||||
|
||||
temp_node.next_node = new_node # type: ignore
|
||||
temp_node.next_node = new_node
|
||||
return head
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ the boundary of the Mandelbrot set a fractal curve.
|
|||
|
||||
import colorsys
|
||||
|
||||
from PIL import Image # type: ignore
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def get_distance(x: float, y: float, max_step: int) -> float:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# https://www.tutorialspoint.com/computer_graphics/computer_graphics_curves.htm
|
||||
from __future__ import annotations
|
||||
|
||||
from scipy.special import comb # type: ignore
|
||||
from scipy.special import comb
|
||||
|
||||
|
||||
class BezierCurve:
|
||||
|
|
|
@ -96,8 +96,8 @@ def analyze_text(text: str) -> tuple[dict, dict]:
|
|||
The first dictionary stores the frequency of single character strings.
|
||||
The second dictionary stores the frequency of two character strings.
|
||||
"""
|
||||
single_char_strings = Counter() # type: ignore
|
||||
two_char_strings = Counter() # type: ignore
|
||||
single_char_strings = Counter() # type: ignore[var-annotated]
|
||||
two_char_strings = Counter() # type: ignore[var-annotated]
|
||||
single_char_strings[text[-1]] += 1
|
||||
|
||||
# first case when we have space at start.
|
||||
|
|
|
@ -116,7 +116,9 @@ def spiral_traversal(matrix: list[list]) -> list[int]:
|
|||
[1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] + spiral_traversal([])
|
||||
"""
|
||||
if matrix:
|
||||
return list(matrix.pop(0)) + spiral_traversal(list(zip(*matrix))[::-1]) # type: ignore
|
||||
return list(matrix.pop(0)) + spiral_traversal(
|
||||
[list(row) for row in zip(*matrix)][::-1]
|
||||
)
|
||||
else:
|
||||
return []
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import logging
|
|||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pytest # type: ignore
|
||||
import pytest
|
||||
|
||||
# Custom/local libraries
|
||||
from matrix import matrix_operation as matop
|
||||
|
|
|
@ -68,7 +68,7 @@ def chain(number: int) -> bool:
|
|||
"""
|
||||
|
||||
if CHAINS[number - 1] is not None:
|
||||
return CHAINS[number - 1] # type: ignore
|
||||
return CHAINS[number - 1] # type: ignore[return-value]
|
||||
|
||||
number_chain = chain(next_number(number))
|
||||
CHAINS[number - 1] = number_chain
|
||||
|
|
|
@ -15,7 +15,7 @@ the last nine digits are 1-9 pandigital, find k.
|
|||
|
||||
import sys
|
||||
|
||||
sys.set_int_max_str_digits(0) # type: ignore
|
||||
sys.set_int_max_str_digits(0)
|
||||
|
||||
|
||||
def check(number: int) -> bool:
|
||||
|
|
|
@ -6,7 +6,6 @@ lint.ignore = [ # `ruff rule S101` for a description of that rule
|
|||
"EM101", # Exception must not use a string literal, assign to variable first
|
||||
"EXE001", # Shebang is present but file is not executable" -- FIX ME
|
||||
"G004", # Logging statement uses f-string
|
||||
"PGH003", # Use specific rule codes when ignoring type issues -- FIX ME
|
||||
"PLC1901", # `{}` can be simplified to `{}` as an empty string is falsey
|
||||
"PLW060", # Using global for `{name}` but no assignment is done -- DO NOT FIX
|
||||
"PLW2901", # PLW2901: Redefined loop variable -- FIX ME
|
||||
|
|
|
@ -4,7 +4,7 @@ import os
|
|||
try:
|
||||
from .build_directory_md import good_file_paths
|
||||
except ImportError:
|
||||
from build_directory_md import good_file_paths # type: ignore
|
||||
from build_directory_md import good_file_paths # type: ignore[no-redef]
|
||||
|
||||
filepaths = list(good_file_paths())
|
||||
assert filepaths, "good_file_paths() failed!"
|
||||
|
|
|
@ -21,8 +21,8 @@ with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
|
|||
def convert_path_to_module(file_path: pathlib.Path) -> ModuleType:
|
||||
"""Converts a file path to a Python module"""
|
||||
spec = importlib.util.spec_from_file_location(file_path.name, str(file_path))
|
||||
module = importlib.util.module_from_spec(spec) # type: ignore
|
||||
spec.loader.exec_module(module) # type: ignore
|
||||
module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
|
||||
spec.loader.exec_module(module) # type: ignore[union-attr]
|
||||
return module
|
||||
|
||||
|
||||
|
@ -92,7 +92,7 @@ def test_project_euler(solution_path: pathlib.Path) -> None:
|
|||
problem_number: str = solution_path.parent.name[8:].zfill(3)
|
||||
expected: str = PROBLEM_ANSWERS[problem_number]
|
||||
solution_module = convert_path_to_module(solution_path)
|
||||
answer = str(solution_module.solution()) # type: ignore
|
||||
answer = str(solution_module.solution())
|
||||
answer = hashlib.sha256(answer.encode()).hexdigest()
|
||||
assert (
|
||||
answer == expected
|
||||
|
|
|
@ -7,7 +7,7 @@ more convenient to use in Python web projects (e.g. Django or Flask-based)
|
|||
from typing import NamedTuple
|
||||
|
||||
import requests
|
||||
from lxml import html # type: ignore
|
||||
from lxml import html
|
||||
|
||||
|
||||
class CovidData(NamedTuple):
|
||||
|
|
Loading…
Reference in New Issue
Block a user