From 1768fa3bd8f45bd389c0fa9f701d73e73dad943b Mon Sep 17 00:00:00 2001 From: selmanozleyen Date: Sat, 20 Jun 2026 16:03:38 +0200 Subject: [PATCH] refactor: drop GraphMatrixT export and make GraphPostprocessor a PEP 695 type alias Follow-up to #1222, which deliberately left these two breaking changes out. Now that the graph-builder API is still experimental, apply both: - Drop `GraphMatrixT` from `squidpy.gr` and `squidpy.gr.neighbors` `__all__` (and remove it from the autosummary in docs/api.md). It was only exported to back the `GraphPostprocessor` alias. - Convert `GraphPostprocessor` to a PEP 695 `type` alias whose type parameter is scoped to the alias itself. This removes the now-unused module-level `GraphMatrixT`/`TypeVar`. Runtime type of `GraphPostprocessor` changes from a plain `typing` form to `TypeAliasType`. Co-Authored-By: Claude Opus 4.8 --- docs/api.md | 2 -- src/squidpy/gr/__init__.py | 2 -- src/squidpy/gr/neighbors.py | 10 ++++------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/api.md b/docs/api.md index c91ff4c22..52c1e03a6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -23,7 +23,6 @@ import squidpy as sq gr.spatial_neighbors_radius gr.spatial_neighbors_delaunay gr.spatial_neighbors_grid - gr.GraphMatrixT gr.SpatialNeighborsResult gr.mask_graph gr.nhood_enrichment @@ -129,7 +128,6 @@ See the {doc}`extensibility guide ` for how to implement a custo gr.neighbors.GraphBuilder gr.neighbors.GraphBuilderCSR - gr.neighbors.GraphMatrixT gr.neighbors.GraphPostprocessor gr.neighbors.DistanceIntervalPostprocessor gr.neighbors.PercentilePostprocessor diff --git a/src/squidpy/gr/__init__.py b/src/squidpy/gr/__init__.py index 6216159d3..fce615b66 100644 --- a/src/squidpy/gr/__init__.py +++ b/src/squidpy/gr/__init__.py @@ -24,10 +24,8 @@ from squidpy.gr._ppatterns import co_occurrence, spatial_autocorr from squidpy.gr._ripley import ripley from squidpy.gr._sepal import sepal -from squidpy.gr.neighbors import GraphMatrixT __all__ = [ - "GraphMatrixT", "SpatialNeighborsResult", "NhoodEnrichmentResult", "neighbors", diff --git a/src/squidpy/gr/neighbors.py b/src/squidpy/gr/neighbors.py index 5a2bb7514..96dbee495 100644 --- a/src/squidpy/gr/neighbors.py +++ b/src/squidpy/gr/neighbors.py @@ -9,7 +9,7 @@ from abc import ABC, abstractmethod from collections.abc import Callable, Sequence from dataclasses import dataclass -from typing import Any, TypeVar, cast +from typing import Any, cast import numpy as np from fast_array_utils import stats as fau_stats @@ -31,7 +31,6 @@ from squidpy._validators import assert_positive __all__ = [ - "GraphMatrixT", "GraphBuilder", "GraphBuilderCSR", "GraphPostprocessor", @@ -45,10 +44,9 @@ ] -# Kept module-level (not folded into GraphBuilder's params): types the public -# `GraphPostprocessor` alias and is itself a public `squidpy.gr` export. -GraphMatrixT = TypeVar("GraphMatrixT") -GraphPostprocessor = Callable[[GraphMatrixT, GraphMatrixT], tuple[GraphMatrixT, GraphMatrixT]] +# Public PEP 695 type alias for graph postprocessors. The type parameter is +# scoped to the alias itself, so no module-level `TypeVar` is needed. +type GraphPostprocessor[GraphMatrixT] = Callable[[GraphMatrixT, GraphMatrixT], tuple[GraphMatrixT, GraphMatrixT]] class GraphBuilder[CoordT, GraphMatrixT](ABC):