Skip to content

Fix type annotation for DataVariables to use Hashable instead of Any#10960

Merged
dcherian merged 1 commit intopydata:mainfrom
dhruvak001:issue#10906
Dec 2, 2025
Merged

Fix type annotation for DataVariables to use Hashable instead of Any#10960
dcherian merged 1 commit intopydata:mainfrom
dhruvak001:issue#10906

Conversation

@dhruvak001
Copy link
Contributor

Currently. using [Any] also disables type checking, making it harder to catch type-related errors. Updated the type annotation in [dataset_variables.py] to use instead of [Any], making it consistent with hashables.

@dcherian dcherian merged commit d42c464 into pydata:main Dec 2, 2025
37 checks passed
jsignell pushed a commit to jsignell/xarray that referenced this pull request Dec 2, 2025
…ydata#10960)

Co-authored-by: DHRUVA KUMAR KAUSHAL <sanjay@MacBook-Air.local>
@mjwillson
Copy link
Contributor

Just FYI, there's a lot of user code out there which assumes the keys/variable names in a Dataset are strings, which fails to typecheck after this change.

I get that having stricter checks here is probably the best decision for type-checking of xarray itself, but for a lot of users who only use string keys the Hashable thing is a bit of a pain and the Any type was a nice compromise.

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.

dataset.data_vars.keys() returns KeysView[Any]

3 participants