Convert remaining generics to PEP 695 syntax#1222
Open
timtreis wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1221. Removes the
UP046/UP047ruff ignore added there by converting the three remainingGeneric[...]/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-unusedCoordTTypeVar. The module-levelGraphMatrixTTypeVar stays - it backs the publicGraphPostprocessoralias and is itself exported (squidpy.gr.GraphMatrixT).gr/_build.py:class SpatialNeighborsResult(NamedTuple, Generic[GraphMatrixT])->class SpatialNeighborsResult[GraphMatrixT](NamedTuple). The importedGraphMatrixTstays (re-exported via__all__).experimental/utils/_params.py:resolve_params->def resolve_params[T](...); drops the module_TTypeVar.pyproject.toml: removes theUP046/UP047ignore.Deliberately not done (would change behaviour)
GraphMatrixTfrom__all__(breaking import change).GraphPostprocessorto atypealias (changes its runtime type).Verification
ruff check .clean with UP046/UP047 active; pre-commit clean.Genericimport removals).tests/graph/test_spatial_neighbors.py+tests/experimental/test_tiling_stitch.py: 65 passed on 3.13.NamedTuple/class/function verified on a real 3.12 interpreter (the new floor) - construct/unpack/_fields/subscription all behave identically.Rebase onto
mainonce #1221 merges.