Skip to content

Commit deb7116

Browse files
authored
[mypy] Fix type annotations for linked_stack.py, evaluate_postfix_notations.py, stack.py in data structures (TheAlgorithms#4409)
* [mypy] Fix type annotations for linked_stack.py, next_greater_element.py, stack.py * Reformatted files according to black
1 parent 727341e commit deb7116

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

data_structures/stacks/evaluate_postfix_notations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, List
2+
13
"""
24
The Reverse Polish Nation also known as Polish postfix notation
35
or simply postfix notation.
@@ -21,7 +23,7 @@ def evaluate_postfix(postfix_notation: list) -> int:
2123
return 0
2224

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

2628
for token in postfix_notation:
2729
if token in operations:

data_structures/stacks/linked_stack.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" A Stack using a linked list like structure """
2-
from typing import Any
2+
from typing import Any, Optional
33

44

55
class Node:
@@ -42,7 +42,7 @@ class LinkedStack:
4242
"""
4343

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

4747
def __iter__(self):
4848
node = self.top
@@ -134,6 +134,8 @@ def peek(self) -> Any:
134134
"""
135135
if self.is_empty():
136136
raise IndexError("peek from empty stack")
137+
138+
assert self.top is not None
137139
return self.top.data
138140

139141
def clear(self) -> None:

data_structures/stacks/stack.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import List
2+
3+
14
class StackOverflowError(BaseException):
25
pass
36

@@ -12,7 +15,7 @@ class Stack:
1215
"""
1316

1417
def __init__(self, limit: int = 10):
15-
self.stack = []
18+
self.stack: List[int] = []
1619
self.limit = limit
1720

1821
def __bool__(self) -> bool:

0 commit comments

Comments
 (0)