Skip to content

Conversation

@jl-wynen
Copy link
Member

@jl-wynen jl-wynen commented Dec 8, 2025

dict is invariant and so we can basically never match the value types in this case. E.g., in

def foo(d: dict[str, int | str]): ...

foo({'a': 3})      # argument is dict[str, int]
foo({'a': 'abc'})  # argument is dict[str, str]

both calls fail to type check because the argument does not exactly match the annotation of foo.
This PR switches to using Mapping which is covariant and so both calls above pass.

There are likely more cases of this in Scipp, but this is at least a start.

@jl-wynen jl-wynen enabled auto-merge December 8, 2025 16:47
@jl-wynen jl-wynen merged commit 6f2e218 into main Dec 8, 2025
4 checks passed
@jl-wynen jl-wynen deleted the fit-covariant-mapping-type branch December 8, 2025 19:42
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.

3 participants