Skip to content

Convert remaining generics to PEP 695 syntax#1222

Open
timtreis wants to merge 3 commits into
chore/bump-min-python-3.12from
refactor/pep695-generics
Open

Convert remaining generics to PEP 695 syntax#1222
timtreis wants to merge 3 commits into
chore/bump-min-python-3.12from
refactor/pep695-generics

Conversation

@timtreis

Copy link
Copy Markdown
Member

Stacked on #1221. Removes the UP046/UP047 ruff ignore added there by converting the three remaining Generic[...] / TypeVar-signature definitions to PEP 695 inline type parameters.

No behaviour or public-API change - type parameters are erased at runtime, and every exported name is preserved.

Changes

  • gr/neighbors.py: class GraphBuilder(ABC, Generic[CoordT, GraphMatrixT]) -> class GraphBuilder[CoordT, GraphMatrixT](ABC). Drops the private, now-unused CoordT TypeVar. The module-level GraphMatrixT TypeVar stays - it backs the public GraphPostprocessor alias and is itself exported (squidpy.gr.GraphMatrixT).
  • gr/_build.py: class SpatialNeighborsResult(NamedTuple, Generic[GraphMatrixT]) -> class SpatialNeighborsResult[GraphMatrixT](NamedTuple). The imported GraphMatrixT stays (re-exported via __all__).
  • experimental/utils/_params.py: resolve_params -> def resolve_params[T](...); drops the module _T TypeVar.
  • pyproject.toml: removes the UP046/UP047 ignore.

Deliberately not done (would change behaviour)

  • Dropping GraphMatrixT from __all__ (breaking import change).
  • Converting GraphPostprocessor to a type alias (changes its runtime type).

Verification

  • ruff check . clean with UP046/UP047 active; pre-commit clean.
  • Public exports unchanged (diff vs base is only the two Generic import removals).
  • tests/graph/test_spatial_neighbors.py + tests/experimental/test_tiling_stitch.py: 65 passed on 3.13.
  • PEP 695 generic NamedTuple/class/function verified on a real 3.12 interpreter (the new floor) - construct/unpack/_fields/subscription all behave identically.

Rebase onto main once #1221 merges.

timtreis added 3 commits June 19, 2026 20:27
Drops the UP046/UP047 ignore by inlining type parameters. Behaviour and the
public API are unchanged (type params are erased at runtime).

- GraphBuilder -> class GraphBuilder[CoordT, GraphMatrixT](ABC); drop the now
  private/unused CoordT TypeVar. The module-level GraphMatrixT TypeVar stays:
  it backs the public GraphPostprocessor alias and is itself exported.
- SpatialNeighborsResult -> class SpatialNeighborsResult[GraphMatrixT](NamedTuple);
  the imported GraphMatrixT remains (re-exported via __all__).
- resolve_params -> def resolve_params[T](...); drop the module _T TypeVar.
- Remove the UP046/UP047 ruff ignore.

Verified: ruff clean, public exports unchanged, functional tests pass, and the
PEP 695 generic NamedTuple/class/function behave identically on 3.12 and 3.13.
_build no longer references the imported GraphMatrixT (SpatialNeighborsResult
declares its own PEP 695 param), so route the public re-export through
gr/__init__ from gr.neighbors and drop the pass-through import + __all__ entry
in _build. squidpy.gr.GraphMatrixT is unchanged.
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