vision icon indicating copy to clipboard operation
vision copied to clipboard

WeightsEnum.get_state_dict: fix return type

Open adamjstewart opened this issue 1 month ago • 3 comments

https://docs.pytorch.org/docs/stable/hub.html#torch.hub.load_state_dict_from_url returns dict[str, Any], which is more specific than Mapping[str, Any].

adamjstewart avatar Nov 29 '25 16:11 adamjstewart

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9286

Note: Links to docs will display an error until the docs builds have been completed.

:heavy_exclamation_mark: 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

pytorch-bot[bot] avatar Nov 29 '25 16:11 pytorch-bot[bot]

Thanks for the PR, CI has been disabled so I can't validate the changes for now - feel free to ping again in a few days.

Out of curiosity though, what's the actual value of changing the type from Mapping to dict? It's more specific, but why is it better? This is a genuine question, I'm not trying to be snarky.

NicolasHug avatar Dec 01 '25 11:12 NicolasHug

Mapping supports __getitem__, but does not support __setitem__ (docs). In our case (TorchGeo), we want to be able to later insert more values into this dictionary. The type checker is currently complaining that this isn't allowed.

adamjstewart avatar Dec 01 '25 12:12 adamjstewart

@NicolasHug anything else needed to merge this PR?

adamjstewart avatar Dec 18 '25 15:12 adamjstewart