Skip to content

Commit 1ae5abf

Browse files
cclaussgithub-actions
and
github-actions
authored
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

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@
525525
* [Perfect Cube](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_cube.py)
526526
* [Perfect Number](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_number.py)
527527
* [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py)
528+
* [Persistence](https://github.com/TheAlgorithms/Python/blob/master/maths/persistence.py)
528529
* [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py)
529530
* [Pollard Rho](https://github.com/TheAlgorithms/Python/blob/master/maths/pollard_rho.py)
530531
* [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py)

data_structures/linked_list/__init__.py

+3-2
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

+4-2
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

+4-2
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

+2-2
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
from __future__ import annotations
2+
13
from math import gcd
2-
from typing import Union
34

45

56
def pollard_rho(
67
num: int,
78
seed: int = 2,
89
step: int = 1,
910
attempts: int = 3,
10-
) -> Union[int, None]:
11+
) -> int | None:
1112
"""
1213
Use Pollard's Rho algorithm to return a nontrivial factor of ``num``.
1314
The returned factor may be composite and require further factorization.

0 commit comments

Comments
 (0)