Skip to content

Remove curried methods and toolz library - #31

Merged
heinrich10 merged 4 commits into
mainfrom
refactor/replace_curry_with_typed
Jun 12, 2026
Merged

Remove curried methods and toolz library#31
heinrich10 merged 4 commits into
mainfrom
refactor/replace_curry_with_typed

Conversation

@heinrich10

Copy link
Copy Markdown
Owner

What?

Replaces the curried extract_query / extract_sort helpers in repositories/base.py with fully typed generic functions, and removes the now-unused toolz library from project dependencies.

Files changed:

  • pyfastapi/repositories/base.py — removed @curry decorators, added TypeVar for type-safe generics
  • pyfastapi/repositories/country.py — replaced toolz.compose with direct sequential calls
  • pyfastapi/repositories/person.py — replaced toolz.compose with direct sequential calls
  • tests/unit_tests/repositories/test_base.py — updated tests to call functions with all arguments
  • pyproject.toml — removed toolz dependency
  • uv.lock — regenerated without toolz

Why?

  • The toolz.curry approach required # type: ignore annotations, breaking mypy --strict safety
  • Functional composition via toolz.compose was unnecessarily complex for simple SQLAlchemy query building
  • toolz was the only remaining consumer of functional-programming patterns in the repository layer; removing it reduces external dependencies

How?

Before — partial application via currying:

@curry  # type: ignore
def extract_query(model, use_like_list, q, stmt): ...

# Usage:
from toolz.functoolz import compose
f = compose(extract_query(Person, [...], q), extract_sort(Person, ..., sort))
stmt = f(select(Person))

After — plain generic functions with a TypeVar:

T = TypeVar("T", bound=Base)

def extract_query(model: Type[T], ..., stmt: Select[Tuple[T]]) -> Select[Tuple[T]]: ...

# Usage:
stmt = select(Person)
stmt = extract_sort(Person, SortPersonEnum, sort, stmt)
stmt = extract_query(Person, [...], q, stmt)

Testing?

  • uv run pytest65/65 tests pass
  • uv run flake8 .0 issues
  • uv run mypy --strict .0 errors across 51 source files

Screenshots (optional)

N/A — internal refactor only.

Anything Else?

  • No behavioral changes; generated SQL is identical before and after
  • toolz is no longer imported anywhere in pyfastapi/ or tests/

AI Summary (optional)

Refactored repository query builders from toolz-based curried functions to plain typed generics, eliminating # type: ignore annotations and removing the toolz runtime dependency entirely.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1217 1198 98% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
pyfastapi/repositories/base.py 100% 🟢
pyfastapi/repositories/country.py 100% 🟢
pyfastapi/repositories/person.py 100% 🟢
tests/unit_tests/repositories/test_base.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 7094d7c by action🐍

@heinrich10
heinrich10 merged commit d3cf154 into main Jun 12, 2026
1 check passed
@heinrich10
heinrich10 deleted the refactor/replace_curry_with_typed branch June 12, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant