Replace typing.optional with new annotations syntax (#5829) · zinating/algorithms-python@1ae5abf · GitHub
Skip to content

Commit 1ae5abf

Browse files
cclaussgithub-actions
andauthored
Replace typing.optional with new annotations syntax (TheAlgorithms#5829)
* Replace typing.optional with new annotations syntax * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent d848bfb commit 1ae5abf

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

DIRECTORY.md

Lines changed: 1 addition & 0 deletions

data_structures/linked_list/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
head node gives us access of the complete list
66
- Last node: points to null
77
"""
8+
from __future__ import annotations
89

9-
from typing import Any, Optional
10+
from typing import Any
1011

1112

1213
class Node:
@@ -17,7 +18,7 @@ def __init__(self, item: Any, next: Any) -> None:
1718

1819
class LinkedList:
1920
def __init__(self) -> None:
20-
self.head: Optional[Node] = None
21+
self.head: Node | None = None
2122
self.size = 0
2223

2324
def add(self, item: Any) -> None:

data_structures/linked_list/circular_linked_list.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from typing import Any, Iterator, Optional
1+
from __future__ import annotations
2+
3+
from typing import Any, Iterator
24

35

46
class Node:
57
def __init__(self, data: Any):
68
self.data: Any = data
7-
self.next: Optional[Node] = None
9+
self.next: Node | None = None
810

911

1012
class CircularLinkedList:

data_structures/linked_list/has_loop.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, Optional
1+
from __future__ import annotations
2+
3+
from typing import Any
24

35

46
class ContainsLoopError(Exception):
@@ -8,7 +10,7 @@ class ContainsLoopError(Exception):
810
class Node:
911
def __init__(self, data: Any) -> None:
1012
self.data: Any = data
11-
self.next_node: Optional[Node] = None
13+
self.next_node: Node | None = None
1214

1315
def __iter__(self):
1416
node = self

data_structures/linked_list/middle_element_of_linked_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from __future__ import annotations
22

33

44
class Node:
@@ -17,7 +17,7 @@ def push(self, new_data: int) -> int:
1717
self.head = new_node
1818
return self.head.data
1919

20-
def middle_element(self) -> Optional[int]:
20+
def middle_element(self) -> int | None:
2121
"""
2222
>>> link = LinkedList()
2323
>>> link.middle_element()

maths/pollard_rho.py

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)