Pyupgrade to Python 3.9 (#4718)

* Pyupgrade to Python 3.9

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2021-09-07 13:37:03 +02:00
committed by GitHub
parent 5d5831bdd0
commit cecf43d648
142 changed files with 523 additions and 530 deletions

View File

@ -1,5 +1,6 @@
from __future__ import annotations
from collections import deque
from typing import Dict, List, Union
class Automaton:
@ -13,7 +14,7 @@ class Automaton:
self.add_keyword(keyword)
self.set_fail_transitions()
def find_next_state(self, current_state: int, char: str) -> Union[int, None]:
def find_next_state(self, current_state: int, char: str) -> int | None:
for state in self.adlist[current_state]["next_states"]:
if char == self.adlist[state]["value"]:
return state
@ -63,7 +64,7 @@ class Automaton:
+ self.adlist[self.adlist[child]["fail_state"]]["output"]
)
def search_in(self, string: str) -> Dict[str, List[int]]:
def search_in(self, string: str) -> dict[str, list[int]]:
"""
>>> A = Automaton(["what", "hat", "ver", "er"])
>>> A.search_in("whatever, err ... , wherever")

View File

@ -17,7 +17,7 @@ Time Complexity : O(n/m)
n=length of main string
m=length of pattern string
"""
from typing import List
from __future__ import annotations
class BoyerMooreSearch:
@ -59,7 +59,7 @@ class BoyerMooreSearch:
return currentPos + i
return -1
def bad_character_heuristic(self) -> List[int]:
def bad_character_heuristic(self) -> list[int]:
# searches pattern in text and returns index positions
positions = []
for i in range(self.textLen - self.patLen + 1):

View File

@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations
def kmp(pattern: str, text: str) -> bool:
@ -36,7 +36,7 @@ def kmp(pattern: str, text: str) -> bool:
return False
def get_failure_array(pattern: str) -> List[int]:
def get_failure_array(pattern: str) -> list[int]:
"""
Calculates the new index we should go to if we fail a comparison
:param pattern: