Skip to content

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

@jonaslb

Description

@jonaslb

What is your issue?

As the title says, this is because DataVariables implements Mapping[Any, "DataArray"].
However, it actually has a variables attribute which returns Mapping[Hashable, Variable], even though it uses the same keys.

So - I'm guessing that DataVariables should actually implement Mapping[Hashable, "DataArray"] instead? Having better types makes it a lot easier to use the APIs, hence why I'm marking this as an issue.

By the way, it's my opinion that Any is problematic in general because it disables type checking. object works the same ("anything"), but doesn't disable type checking, so it is better to use this. Although "appropriately narrower" types are even better, of course. Is this an area you would accept PRs on, hypothetically? For example with gradual introduction of a rule like disallow_any_explicit? Maybe that's a too wide question for a more narrow issue :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions