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,4 +1,6 @@
from typing import Iterable, List, Optional
from __future__ import annotations
from typing import Iterable
class Heap:
@ -25,19 +27,19 @@ class Heap:
"""
def __init__(self) -> None:
self.h: List[float] = []
self.h: list[float] = []
self.heap_size: int = 0
def __repr__(self) -> str:
return str(self.h)
def parent_index(self, child_idx: int) -> Optional[int]:
def parent_index(self, child_idx: int) -> int | None:
"""return the parent index of given child"""
if child_idx > 0:
return (child_idx - 1) // 2
return None
def left_child_idx(self, parent_idx: int) -> Optional[int]:
def left_child_idx(self, parent_idx: int) -> int | None:
"""
return the left child index if the left child exists.
if not, return None.
@ -47,7 +49,7 @@ class Heap:
return left_child_index
return None
def right_child_idx(self, parent_idx: int) -> Optional[int]:
def right_child_idx(self, parent_idx: int) -> int | None:
"""
return the right child index if the right child exists.
if not, return None.