Skip to content

Modernize safe uses of TypeVar/ParamSpec/TypeVarTuple to PEP 695 syntax - #11768

Open
FrancescoPezzella wants to merge 4 commits into
pydata:mainfrom
FrancescoPezzella:type-param-modernization
Open

FrancescoPezzella wants to merge 4 commits into
pydata:mainfrom
FrancescoPezzella:type-param-modernization

Conversation

@FrancescoPezzella

@FrancescoPezzella FrancescoPezzella commented Oct 20, 2026 •

Copy link
Copy Markdown

Convert type parameters to PEP 695 syntax in 8 files (Python 3.12+).

  • converted to PEP 695 in functions: T (4 files), P (2 files), C, F, T_FacetGrid, T_PandasIndex, T_Resample
  • unused declaration removed: T_FreqStr

Description

Checklist

AI Disclosure

This PR does not contain any AI usage. Instead, I utilize a tool of this experimental framework - https://github.com/TNO/Renaissance.Py

@github-actions github-actions Bot added topic-indexing topic-plotting topic-cftime topic-DataTree Related to the implementation of a DataTree class labels Oct 20, 2026
@FrancescoPezzella FrancescoPezzella changed the title Modernize TypeVar/ParamSpec/TypeVarTuple usage to PEP 695 syntax Modernize safe uses of TypeVar/ParamSpec/TypeVarTuple to PEP 695 syntax Oct 20, 2026
Comment thread xarray/plot/facetgrid.py Outdated
@github-actions github-actions Bot added the topic-NamedArray Lightweight version of Variable label Oct 21, 2026
@FrancescoPezzella

FrancescoPezzella commented Oct 21, 2026 •

Copy link
Copy Markdown
Author

Interesting... changing the Type Parameters to Self exposed some underlying issues with other methods that weren't caught before in facetgrid.py

FacetGrid[Any] -> FacetGrid[T_DataArrayOrSet]

Now with the generic parameter being reserved it seems that map_plot1d and map_dataarray_line were expecting a DataArray and this wasn't being caught with the Any subtype.

Argument of type "Dataset* | Unknown" cannot be assigned to parameter "darray" of type "DataArray" in function "_infer_line_data"
  Type "Dataset* | Unknown" is not assignable to type "DataArray"
    "Dataset*" is not assignable to "DataArray"

Should this be fixed in this PR? Since the Ci/Cd is failing for now

@headtr1ck headtr1ck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

FrancescoPezzella and others added 4 commits October 26, 2026 12:58
Convert type parameters to PEP 695 syntax in 8 files (Python 3.12+).

- converted to PEP 695 in functions: T (4 files), P (2 files), C, F, T_FacetGrid, T_PandasIndex, T_Resample
- unused declaration removed: T_FreqStr
Note: The command only works if it sees `from typing import Self` and it is not inside a TYPE_CHECKING block

Replace `from xarray.core.types import Self` with `from typing import Self`

Note: There might be more instances of this, this was just a quick search with direct matches, also used `ruff check --isolated --select I001 --target-version py312 --fix` to re-organize said imports
@FrancescoPezzella
FrancescoPezzella marked this pull request as ready for review October 26, 2026 11:58
@FrancescoPezzella

Copy link
Copy Markdown
Author

Thanks!

hi im a bit confused with this response

@headtr1ck

Copy link
Copy Markdown
Collaborator

Thanks!

hi im a bit confused with this response

Just saying that once we fix mypy this is good to go!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-cftime topic-DataTree Related to the implementation of a DataTree class topic-indexing topic-NamedArray Lightweight version of Variable topic-plotting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants