Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion data_structures/stacks/evaluate_postfix_notations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, List

"""
The Reverse Polish Nation also known as Polish postfix notation
or simply postfix notation.
Expand All @@ -21,7 +23,7 @@ def evaluate_postfix(postfix_notation: list) -> int:
return 0

operations = {"+", "-", "*", "/"}
stack = []
stack: List[Any] = []

for token in postfix_notation:
if token in operations:
Expand Down
6 changes: 4 additions & 2 deletions data_structures/stacks/linked_stack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" A Stack using a linked list like structure """
from typing import Any
from typing import Any, Optional


class Node:
Expand Down Expand Up @@ -42,7 +42,7 @@ class LinkedStack:
"""

def __init__(self) -> None:
self.top = None
self.top: Optional[Node] = None

def __iter__(self):
node = self.top
Expand Down Expand Up @@ -134,6 +134,8 @@ def peek(self) -> Any:
"""
if self.is_empty():
raise IndexError("peek from empty stack")

assert self.top is not None
return self.top.data

def clear(self) -> None:
Expand Down
5 changes: 4 additions & 1 deletion data_structures/stacks/stack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List


class StackOverflowError(BaseException):
pass

Expand All @@ -12,7 +15,7 @@ class Stack:
"""

def __init__(self, limit: int = 10):
self.stack = []
self.stack: List[int] = []
self.limit = limit

def __bool__(self) -> bool:
Expand Down