[mypy] Fix type annotations for linked_stack.py, evaluate_postfix_not… · zinating/algorithms-python@deb7116 · GitHub
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

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

data_structures/stacks/evaluate_postfix_notations.py

Lines changed: 3 additions & 1 deletion

data_structures/stacks/linked_stack.py

Lines changed: 4 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion

0 commit comments

Comments
 (0)