Skip to content
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
40 changes: 40 additions & 0 deletions src/algorithms/searching/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Searching algorithms (lightweight top-level namespace).

Provides lazy accessors for submodules to avoid circular import issues.
"""

from importlib import import_module
from typing import Any

__all__ = [
"advanced_search",
"binary_search",
"linear_search",
"quickselect",
]


def __getattr__(name: str) -> Any:
"""
Lazily import and expose searching submodules as attributes:
- advanced_search
- binary_search
- linear_search
- quickselect
"""
if name in __all__:
import sys

canonical = f"interview_workbook.algorithms.searching.{name}"
# If already imported under canonical path, reuse it to avoid reload/circulars
if canonical in sys.modules:
return sys.modules[canonical]
# Try canonical import first
try:
return import_module(canonical)
except ModuleNotFoundError:
# Fallback to local under src/ if present
local = f"{__name__}.{name}"
return import_module(local)
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
3 changes: 3 additions & 0 deletions src/algorithms/searching/advanced_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook searching under src.algorithms.searching.*
# This enables tests importing src.algorithms.searching.* to resolve correctly.
from interview_workbook.algorithms.searching.advanced_search import * # noqa: F401,F403
3 changes: 3 additions & 0 deletions src/algorithms/searching/binary_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook searching under src.algorithms.searching.*
# This enables tests importing src.algorithms.searching.* to resolve correctly.
from interview_workbook.algorithms.searching.binary_search import * # noqa: F401,F403
3 changes: 3 additions & 0 deletions src/algorithms/searching/linear_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook searching under src.algorithms.searching.*
# This enables tests importing src.algorithms.searching.* to resolve correctly.
from interview_workbook.algorithms.searching.linear_search import * # noqa: F401,F403
3 changes: 3 additions & 0 deletions src/algorithms/searching/quickselect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook searching under src.algorithms.searching.*
# This enables tests importing src.algorithms.searching.* to resolve correctly.
from interview_workbook.algorithms.searching.quickselect import * # noqa: F401,F403
8 changes: 7 additions & 1 deletion src/algorithms/sorting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

__all__ = [
"bubble_sort",
"heap_sort",
"insertion_sort",
"merge_sort",
"non_comparison_sorts",
"quick_sort",
"selection_sort",
]

Expand All @@ -19,9 +22,12 @@ def __getattr__(name: str) -> Any:
"""
Lazily import and expose sorting submodules as attributes:
- bubble_sort
- heap_sort
- insertion_sort
- selection_sort
- merge_sort
- non_comparison_sorts
- quick_sort
- selection_sort
"""
if name in __all__:
import sys
Expand Down
3 changes: 3 additions & 0 deletions src/algorithms/sorting/heap_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.*
# This enables tests importing src.algorithms.sorting.* to resolve correctly.
from interview_workbook.algorithms.sorting.heap_sort import * # noqa: F401,F403
3 changes: 3 additions & 0 deletions src/algorithms/sorting/merge_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.*
# This enables tests importing src.algorithms.sorting.* to resolve correctly.
from interview_workbook.algorithms.sorting.merge_sort import * # noqa: F401,F403
3 changes: 3 additions & 0 deletions src/algorithms/sorting/quick_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Proxy module to expose interview_workbook sorting under src.algorithms.sorting.*
# This enables tests importing src.algorithms.sorting.* to resolve correctly.
from interview_workbook.algorithms.sorting.quick_sort import * # noqa: F401,F403
Loading