Conversation
Python 3.12 is now the minimum, in line with the minimum dependency policy. - Bump requires-python, the classifiers (also adding 3.14), the binder, asv and bug report environments and the installation docs. - Rename the py311 pixi feature and the test-py311* environments to py312 and run the minimum version environments on Python 3.12. - Remove the version checks for Python < 3.12 in NodePath and test_namedarray. - Reformat an f-string that ruff now formats with PEP 701 quoting. - Ignore the PEP 695 ruff rules (UP040, UP046, UP047) that apply now; the migration from TypeVar and TypeAlias is left for a separate change. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Now that Python 3.12 is the minimum, enable the ruff rules UP040, UP046 and UP047 and use type parameters and type statements instead of TypeVar, Generic and TypeAlias. - Classes using the TypeVars shared through xarray.core.types restate their bounds or constraints; the shared TypeVars are kept, as many functions and downstream packages still use them. - NamedArray keeps Generic with its covariant TypeVars: PEP 695 infers variance, and its mutable data makes it invariant. - ResampleCompatible stays a TypeAlias, as it is used in isinstance checks. - Remove the TypeVars that are no longer used, and quotes and Union in bounds and type statements, which are evaluated lazily. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With type statements, aliases can refer to themselves directly, so NestedSequence no longer needs the Protocol copied from numpy, and NestedDict no longer needs a quoted forward reference, which also makes it properly generic at runtime. The stricter NestedSequence showed that _infer_tile_ids_from_nested_list was called with leaves as well; it now only recurses into sequences. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add typing.override (Python >= 3.12) to the methods that override a method of one of xarray's own classes, e.g. of Index, the backend stores and entrypoints, the coders, the cftime offsets, the indexing adapters and Coordinates. Type checkers then report it if the overridden method is renamed or removed. Not covered: overrides of builtins and of the collections.abc and typing ABCs, the generated files, the tests, and properties with a setter, which mypy cannot check yet. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Classes with type parameters have a __type_params__ attribute at runtime, which stubtest reports as missing from the stub, e.g. for xarray.core.dataarray._LocIndexer. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dcherian
approved these changes
Sep 30, 2026
headtr1ck
enabled auto-merge (squash)
October 1, 2026 08:04
Co-authored-by: Claude <noreply@anthropic.com>
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.
Description
Follow-up to #11649 (based on it, so it includes its commits until that is merged), using typing features of Python 3.12:
UP040,UP046andUP047and use PEP 695 type parameters andtypestatements instead ofTypeVar,GenericandTypeAlias.NestedSequenceandNestedDictas recursivetypealiases instead of aProtocoland a quoted forward reference.@typing.override(PEP 698), so type checkers report it when the overridden method is renamed or removed.__type_params__in the stubtest allowlist: classes with type parameters have it at runtime, and stubtest reports it as missing from the stub.Exceptions:
NamedArraykeepsGenericwith its covariant TypeVars: PEP 695 infers variance, and its mutabledatawould make it invariant.ResampleCompatiblestays aTypeAlias, as it is used inisinstancechecks.xarray.core.typesare kept, since they are still used by functions and downstream packages.@overridefor overrides of builtins and thecollections.abc/typingABCs, in generated files and tests, and for properties with a setter, which mypy cannot check yet.mypy and stubtest report no new errors, and the tests pass on Python 3.12 and 3.14.
AI Disclosure
Tools: Claude Code (Claude Opus 5.5)
🤖 Generated with Claude Code