Skip to content

Commit

Permalink
Consolidate stubs into respective __init__.pyi
Browse files Browse the repository at this point in the history
  • Loading branch information
realshouzy committed May 9, 2024
1 parent 0914f6d commit 952574a
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 301 deletions.
68 changes: 48 additions & 20 deletions nrw/algorithms/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,52 @@ __all__: Final[tuple[str, ...]] = (
"levelorder",
)

from typing import Final
from typing import Final, TypeVar, overload

from nrw.algorithms._searching import (
breadth_first_search,
depth_first_search,
linear_search,
)
from nrw.algorithms._sorting import (
bubble_sort,
insertion_sort,
merge_sort,
quick_sort,
selection_sort,
)
from nrw.algorithms._traversal import (
inorder,
levelorder,
postorder,
preorder,
reverse_inorder,
)
from nrw.datastructures._binary_search_tree import BinarySearchTree
from nrw.datastructures._binary_tree import BinaryTree
from nrw.datastructures._comparable_content import ComparableContentT
from nrw.datastructures._graph import Graph
from nrw.datastructures._list import List
from nrw.datastructures._vertex import Vertex

_T = TypeVar("_T")

def linear_search(lst: List[_T], element: _T) -> int: ...
def depth_first_search(graph: Graph, vertex: Vertex) -> List[Vertex]: ...
def breadth_first_search(graph: Graph, vertex: Vertex) -> List[Vertex]: ...
def bubble_sort(lst: List[ComparableContentT]) -> List[ComparableContentT]: ...
def selection_sort(lst: List[ComparableContentT]) -> List[ComparableContentT]: ...
def insertion_sort(lst: List[ComparableContentT]) -> List[ComparableContentT]: ...
def merge_sort(lst: List[ComparableContentT]) -> List[ComparableContentT]: ...
def quick_sort(lst: List[ComparableContentT]) -> List[ComparableContentT]: ...
@overload
def preorder(tree: BinaryTree[_T]) -> List[_T]: ...
@overload
def preorder(
tree: BinarySearchTree[ComparableContentT],
) -> List[ComparableContentT]: ...
@overload
def inorder(tree: BinaryTree[_T]) -> List[_T]: ...
@overload
def inorder(
tree: BinarySearchTree[ComparableContentT],
) -> List[ComparableContentT]: ...
@overload
def reverse_inorder(tree: BinaryTree[_T]) -> List[_T]: ...
@overload
def reverse_inorder(
tree: BinarySearchTree[ComparableContentT],
) -> List[ComparableContentT]: ...
@overload
def postorder(tree: BinaryTree[_T]) -> List[_T]: ...
@overload
def postorder(
tree: BinarySearchTree[ComparableContentT],
) -> List[ComparableContentT]: ...
@overload
def levelorder(tree: BinaryTree[_T]) -> List[_T]: ...
@overload
def levelorder(
tree: BinarySearchTree[ComparableContentT],
) -> List[ComparableContentT]: ...
17 changes: 0 additions & 17 deletions nrw/algorithms/_searching.pyi

This file was deleted.

18 changes: 0 additions & 18 deletions nrw/algorithms/_sorting.pyi

This file was deleted.

44 changes: 0 additions & 44 deletions nrw/algorithms/_traversal.pyi

This file was deleted.

166 changes: 157 additions & 9 deletions nrw/datastructures/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,162 @@ __all__: Final[tuple[str, ...]] = (
"Graph",
)

from typing import Final
from typing import Final, Generic, TypeVar, overload

from nrw.datastructures._binary_search_tree import BinarySearchTree
from nrw.datastructures._binary_tree import BinaryTree
from nrw.datastructures._comparable_content import ComparableContent, ComparableContentT
from nrw.datastructures._edge import Edge
from nrw.datastructures._graph import Graph
from nrw.datastructures._list import List
from nrw.datastructures._queue import Queue
from nrw.datastructures._stack import Stack
from nrw.datastructures._vertex import Vertex

_T = TypeVar("_T")

class Queue(Generic[_T]):
__slots__: Final[tuple[str, str]] = ("_head", "_tail")
__hash__ = None # type: ignore[assignment]

def __init__(self) -> None: ...
@property
def is_empty(self) -> bool: ...
def enqueue(self, content: _T) -> None: ...
def dequeue(self) -> None: ...
@property
def front(self) -> _T | None: ...

class Stack(Generic[_T]):
__slots__: Final[tuple[str]] = ("_head",)
__hash__ = None # type: ignore[assignment]

def __init__(self) -> None: ...
@property
def is_empty(self) -> bool: ...
def push(self, content: _T) -> None: ...
def pop(self) -> None: ...
@property
def top(self) -> _T | None: ...

class List(Generic[_T]):
__slots__: Final[tuple[str, str, str]] = ("_first", "_last", "_current")
__hash__ = None # type: ignore[assignment]

def __init__(self) -> None: ...
@property
def is_empty(self) -> bool: ...
@property
def has_access(self) -> bool: ...
def next(self) -> None: ...
def to_first(self) -> None: ...
def to_last(self) -> None: ...
@property
def content(self) -> _T | None: ...
@content.setter
def content(self, new_content: _T | None) -> None: ...
def insert(self, content: _T | None) -> None: ...
def append(self, content: _T | None) -> None: ...
def concat(self, other_list: List[_T] | None) -> None: ...
def remove(self) -> None: ...

class BinaryTree(Generic[_T]):
__slots__: Final[tuple[str]] = ("_node",)
__hash__ = None # type: ignore[assignment]

@overload
def __init__(self) -> None: ...
@overload
def __init__(
self,
content: _T | None,
) -> None: ...
@overload
def __init__(
self,
content: _T | None,
left_tree: BinaryTree[_T] | None,
right_tree: BinaryTree[_T] | None,
) -> None: ...
@property
def is_empty(self) -> bool: ...
@property
def content(self) -> _T | None: ...
@content.setter
def content(self, new_content: _T | None) -> None: ...
@property
def left_tree(self) -> BinaryTree[_T] | None: ...
@left_tree.setter
def left_tree(self, new_tree: BinaryTree[_T] | None) -> None: ...
@property
def right_tree(self) -> BinaryTree[_T] | None: ...
@right_tree.setter
def right_tree(self, new_tree: BinaryTree[_T] | None) -> None: ...

class BinarySearchTree(Generic[ComparableContentT]):
__slots__: Final[tuple[str]] = ("_node",)
__hash__ = None # type: ignore[assignment]

def __init__(self) -> None: ...
@property
def is_empty(self) -> bool: ...
@property
def content(self) -> ComparableContentT | None: ...
@property
def left_tree(self) -> BinarySearchTree[ComparableContentT] | None: ...
@property
def right_tree(self) -> BinarySearchTree[ComparableContentT] | None: ...
def insert(self, content: ComparableContentT | None) -> None: ...
def remove(self, content: ComparableContentT | None) -> None: ...
def search(
self,
content: ComparableContentT | None,
) -> ComparableContentT | None: ...

class Vertex:
__slots__: Final[tuple[str, str]] = ("_id", "_mark")
__hash__ = None # type: ignore[assignment]

def __init__(self, id_: str) -> None: ...
@property
def id(self) -> str: ...
@property
def mark(self) -> bool: ...
@mark.setter
def mark(self, new_mark: bool) -> None: ...
@property
def is_marked(self) -> bool: ...

class Edge:
__slots__: Final[tuple[str, str, str]] = ("_vertices", "_weight", "_mark")
__hash__ = None # type: ignore[assignment]

def __init__(self, vertex: Vertex, another_vertex: Vertex, weight: int) -> None: ...
@property
def vertices(self) -> tuple[Vertex, Vertex]: ...
@property
def weight(self) -> int: ...
@weight.setter
def weight(self, new_weight: int) -> None: ...
@property
def mark(self) -> bool: ...
@mark.setter
def mark(self, new_mark: bool) -> None: ...
@property
def is_marked(self) -> bool: ...

class Graph:
__slots__: Final[tuple[str, str]] = ("_vertices", "_edges")
__hash__ = None # type: ignore[assignment]

def __init__(self) -> None: ...
@property
def vertices(self) -> List[Vertex]: ...
@property
def edges(self) -> List[Edge]: ...
def get_vertex(self, id_: str) -> Vertex | None: ...
def add_vertex(self, vertex: Vertex | None) -> None: ...
def remove_vertex(self, vertex: Vertex) -> None: ...
def get_edge(self, vertex: Vertex, another_vertex: Vertex) -> Edge | None: ...
def add_edge(self, edge: Edge | None) -> None: ...
def remove_edge(self, edge: Edge) -> None: ...
def set_all_vertex_marks(self, mark: bool) -> None: ...
def all_vertices_marked(self) -> bool: ...
def set_all_edge_marks(self, mark: bool) -> None: ...
def all_edges_marked(self) -> bool: ...
def get_neighbours(self, vertex: Vertex) -> List[Vertex]: ...
def get_edges(self, vertex: Vertex) -> List[Edge]: ...
@property
def is_empty(self) -> bool: ...
23 changes: 0 additions & 23 deletions nrw/datastructures/_binary_search_tree.pyi

This file was deleted.

38 changes: 0 additions & 38 deletions nrw/datastructures/_binary_tree.pyi

This file was deleted.

Loading

0 comments on commit 952574a

Please sign in to comment.