10000 Generic type hint in DDL by isidroas · Pull Request #12677 · TheAlgorithms/Python · GitHub
[go: up one dir, main page]

Skip to content

Generic type hint in DDL #12677

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 3 commits into from
Apr 21, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update doubly_linked_list_two.py
  • Loading branch information
MaximSmolskiy authored Apr 21, 2025
commit f859e6d1748e76663590f2cf686b3277ecbd7d25
12 changes: 6 additions & 6 deletions data_structures/linked_list/doubly_linked_list_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from dataclasses import dataclass
from typing import Self, TypeVar

Data = TypeVar("Data")
DataType = TypeVar("DataType")


@dataclass
class Node[Data]:
data: Data
class Node[DataType]:
data: DataType
previous: Self | None = None
next: Self | None = None

Expand Down Expand Up @@ -54,7 +54,7 @@
current = current.next
return " ".join(str(node) for node in nodes)

def __contains__(self, value: Data):
def __contains__(self, value: DataType):
current = self.head
while current:
if current.data == value:
Expand Down Expand Up @@ -89,7 +89,7 @@
else:
self.insert_after_node(self.tail, node)

def insert(self, value: Data) -> None:
def insert(self, value: DataType) -> None:
node = Node(value)
if self.head is None:
self.set_head(node)
Expand Down Expand Up @@ -118,7 +118,7 @@

node.next = node_to_insert

def insert_at_position(self, position: int, value: Data) -> None:
def insert_at_position(self, position: int, value: DataType) -> None:
current_position = 1
new_node = Node(value)
node = self.head
Expand All @@ -130,7 +130,7 @@
node = node.next
self.set_tail(new_node)

def get_node(self, item: Data) -> Node:

Check failure on line 133 in data_structures/linked_list/doubly_linked_list_two.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

data_structures/linked_list/doubly_linked_list_two.py:133:30: F821 Undefined name `Data`
node = self.head
while node:
if node.data == item:
Expand Down
Loading
0