[mypy] Fix type annotations for linked_stack.py, evaluate_postfix_notations.py, stack.py in data structures (#4409)

* [mypy] Fix type annotations for linked_stack.py, next_greater_element.py, stack.py

* Reformatted files according to black
This commit is contained in:
Ahmed Haj Abdel Khaleq 2021-05-12 02:22:42 -04:00 committed by GitHub
parent 727341e3db
commit deb71167e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -1,3 +1,5 @@
from typing import Any, List
""" """
The Reverse Polish Nation also known as Polish postfix notation The Reverse Polish Nation also known as Polish postfix notation
or simply postfix notation. or simply postfix notation.
@ -21,7 +23,7 @@ def evaluate_postfix(postfix_notation: list) -> int:
return 0 return 0
operations = {"+", "-", "*", "/"} operations = {"+", "-", "*", "/"}
stack = [] stack: List[Any] = []
for token in postfix_notation: for token in postfix_notation:
if token in operations: if token in operations:

View File

@ -1,5 +1,5 @@
""" A Stack using a linked list like structure """ """ A Stack using a linked list like structure """
from typing import Any from typing import Any, Optional
class Node: class Node:
@ -42,7 +42,7 @@ class LinkedStack:
""" """
def __init__(self) -> None: def __init__(self) -> None:
self.top = None self.top: Optional[Node] = None
def __iter__(self): def __iter__(self):
node = self.top node = self.top
@ -134,6 +134,8 @@ class LinkedStack:
""" """
if self.is_empty(): if self.is_empty():
raise IndexError("peek from empty stack") raise IndexError("peek from empty stack")
assert self.top is not None
return self.top.data return self.top.data
def clear(self) -> None: def clear(self) -> None:

View File

@ -1,3 +1,6 @@
from typing import List
class StackOverflowError(BaseException): class StackOverflowError(BaseException):
pass pass
@ -12,7 +15,7 @@ class Stack:
""" """
def __init__(self, limit: int = 10): def __init__(self, limit: int = 10):
self.stack = [] self.stack: List[int] = []
self.limit = limit self.limit = limit
def __bool__(self) -> bool: def __bool__(self) -> bool: