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

@ -14,7 +14,7 @@ def date_to_weekday(inp_date: str) -> str:
>>> date_to_weekday("1/1/2021")
'Friday'
"""
day, month, year = [int(x) for x in inp_date.split("/")]
day, month, year = (int(x) for x in inp_date.split("/"))
if year % 100 == 0:
year = "00"
new_base_date: str = f"{day}/{month}/{year%100} 0:0:0"

View File

@ -8,9 +8,9 @@ conjunctive normal form, i.e, for solving the Conjunctive Normal Form SATisfiabi
For more information about the algorithm: https://en.wikipedia.org/wiki/DPLL_algorithm
"""
from __future__ import annotations
import random
from typing import Dict, List
class Clause:
@ -27,7 +27,7 @@ class Clause:
True
"""
def __init__(self, literals: List[int]) -> None:
def __init__(self, literals: list[int]) -> None:
"""
Represent the literals and an assignment in a clause."
"""
@ -52,7 +52,7 @@ class Clause:
"""
return len(self.literals)
def assign(self, model: Dict[str, bool]) -> None:
def assign(self, model: dict[str, bool]) -> None:
"""
Assign values to literals of the clause as given by model.
"""
@ -68,7 +68,7 @@ class Clause:
value = not value
self.literals[literal] = value
def evaluate(self, model: Dict[str, bool]) -> bool:
def evaluate(self, model: dict[str, bool]) -> bool:
"""
Evaluates the clause with the assignments in model.
This has the following steps:
@ -97,7 +97,7 @@ class Formula:
{{A1, A2, A3'}, {A5', A2', A1}} is ((A1 v A2 v A3') and (A5' v A2' v A1))
"""
def __init__(self, clauses: List[Clause]) -> None:
def __init__(self, clauses: list[Clause]) -> None:
"""
Represent the number of clauses and the clauses themselves.
"""
@ -146,7 +146,7 @@ def generate_formula() -> Formula:
return Formula(set(clauses))
def generate_parameters(formula: Formula) -> (List[Clause], List[str]):
def generate_parameters(formula: Formula) -> (list[Clause], list[str]):
"""
Return the clauses and symbols from a formula.
A symbol is the uncomplemented form of a literal.
@ -173,8 +173,8 @@ def generate_parameters(formula: Formula) -> (List[Clause], List[str]):
def find_pure_symbols(
clauses: List[Clause], symbols: List[str], model: Dict[str, bool]
) -> (List[str], Dict[str, bool]):
clauses: list[Clause], symbols: list[str], model: dict[str, bool]
) -> (list[str], dict[str, bool]):
"""
Return pure symbols and their values to satisfy clause.
Pure symbols are symbols in a formula that exist only
@ -225,8 +225,8 @@ def find_pure_symbols(
def find_unit_clauses(
clauses: List[Clause], model: Dict[str, bool]
) -> (List[str], Dict[str, bool]):
clauses: list[Clause], model: dict[str, bool]
) -> (list[str], dict[str, bool]):
"""
Returns the unit symbols and their values to satisfy clause.
Unit symbols are symbols in a formula that are:
@ -273,8 +273,8 @@ def find_unit_clauses(
def dpll_algorithm(
clauses: List[Clause], symbols: List[str], model: Dict[str, bool]
) -> (bool, Dict[str, bool]):
clauses: list[Clause], symbols: list[str], model: dict[str, bool]
) -> (bool, dict[str, bool]):
"""
Returns the model if the formula is satisfiable, else None
This has the following steps:

View File

@ -1,4 +1,6 @@
from typing import Callable, Optional
from __future__ import annotations
from typing import Callable
class DoubleLinkedListNode:
@ -119,7 +121,7 @@ class LFUCache:
"""
return key in self.cache
def get(self, key: int) -> Optional[int]:
def get(self, key: int) -> int | None:
"""
Returns the value for the input key and updates the Double Linked List. Returns
None if key is not present in cache

View File

@ -1,4 +1,6 @@
from typing import Callable, Optional
from __future__ import annotations
from typing import Callable
class DoubleLinkedListNode:
@ -125,7 +127,7 @@ class LRUCache:
return key in self.cache
def get(self, key: int) -> Optional[int]:
def get(self, key: int) -> int | None:
"""
Returns the value for the input key and updates the Double Linked List. Returns
None if key is not present in cache