Skip to content

Replace typing.optional with new annotations syntax #5829

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
Nov 17, 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
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
* [Perfect Cube](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_cube.py)
* [Perfect Number](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_number.py)
* [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py)
* [Persistence](https://github.com/TheAlgorithms/Python/blob/master/maths/persistence.py)
* [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py)
* [Pollard Rho](https://github.com/TheAlgorithms/Python/blob/master/maths/pollard_rho.py)
* [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py)
Expand Down
5 changes: 3 additions & 2 deletions data_structures/linked_list/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
head node gives us access of the complete list
- Last node: points to null
"""
from __future__ import annotations

from typing import Any, Optional
from typing import Any


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

class LinkedList:
def __init__(self) -> None:
self.head: Optional[Node] = None
self.head: Node | None = None
self.size = 0

def add(self, item: Any) -> None:
Expand Down
6 changes: 4 additions & 2 deletions data_structures/linked_list/circular_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any, Iterator, Optional
from __future__ import annotations

from typing import Any, Iterator


class Node:
def __init__(self, data: Any):
self.data: Any = data
self.next: Optional[Node] = None
self.next: Node | None = None


class CircularLinkedList:
Expand Down
6 changes: 4 additions & 2 deletions data_structures/linked_list/has_loop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Any, Optional
from __future__ import annotations

from typing import Any


class ContainsLoopError(Exception):
Expand All @@ -8,7 +10,7 @@ class ContainsLoopError(Exception):
class Node:
def __init__(self, data: Any) -> None:
self.data: Any = data
self.next_node: Optional[Node] = None
self.next_node: Node | None = None

def __iter__(self):
node = self
Expand Down
4 changes: 2 additions & 2 deletions data_structures/linked_list/middle_element_of_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations


class Node:
Expand All @@ -17,7 +17,7 @@ def push(self, new_data: int) -> int:
self.head = new_node
return self.head.data

def middle_element(self) -> Optional[int]:
def middle_element(self) -> int | None:
"""
>>> link = LinkedList()
>>> link.middle_element()
Expand Down
5 changes: 3 additions & 2 deletions maths/pollard_rho.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from math import gcd
from typing import Union


def pollard_rho(
num: int,
seed: int = 2,
step: int = 1,
attempts: int = 3,
) -> Union[int, None]:
) -> int | None:
"""
Use Pollard's Rho algorithm to return a nontrivial factor of ``num``.
The returned factor may be composite and require further factorization.
Expand Down