You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Mutable list is invariantlist1: list[int] = [10]
list2: list[int|None] =list1# Error# Immutable list (tuple) is covarianttuple1: tuple[int, ...] = (10, )
tuple2: tuple[int|None, ...] =tuple1# No Error# Mutable dict is invariantdict1: dict[str, int] = {"a": 10}
dict2: dict[str, int|None] =dict1# Error # Immutable dict is also invariant????fdict1: frozendict[str, int] =frozendict(**{"a": 10})
fdict2: frozendict[str, int|None] =fdict1# Error# But I think this should not be an error# I think Key and Value should booth be covariant
Python: 3.15
I think a frozen dict should be covariant the same as a tuple is.
If the datatype is readonly, it should always be save to widen the generic Parameters?
As far as i understand, the bundled typeshed types do not declare the Generic Parameters to be covariant.
This is a how it's defined in typeshed (src), so it's not specific to Pyrefly. It might be worth opening an issue there, because as far as I can tell, there isn't an issue or PR for this yet.
Thanks for the report, and thanks @jorenham for pointing at typeshed. The related constructor bug (#4994) is now fixed on main. The invariance here comes from how the bundled typeshed stub declares frozendict's type parameters, so it's a typeshed question rather than a pyrefly one; we'll re-check it after our next stub update.
We've now updated our bundled typeshed, and it still declares frozendict's value type as invariant, so pyrefly will keep reporting this until typeshed changes it. Opening an issue on typeshed, as @jorenham suggested, is the best way to get that fixed, and pyrefly will pick it up with a later stub update.
@IIIMADDINIII Thanks for opening an issue with typeshed. Looks like the stub is now fixed, so this should be fixed the next time we update our bundled typeshed.
Activity
jorenham commentedon Oct 19, 2026
This is a how it's defined in typeshed (src), so it's not specific to Pyrefly. It might be worth opening an issue there, because as far as I can tell, there isn't an issue or PR for this yet.
randolf-scholz commentedon Oct 21, 2026
this should be
frozendict({"a": 10})orfrozendict(**{"a": 10}), no? though it seems pyrefly currently errors on thesehttps://pyrefly.org/sandbox/?project=v2.w1VkgjN-VWpeCrBQ0qiOUUoExoOCoUEtMGSRJLS0UKWQiiINhDI9mOPwqchLLQcrwAxWZYUAiIAC1IXAAgUYH-mlwGILGM56MXnKwBIrVSGjpKSg2EpfH6Y9vyhdPzVPPyU_uVgfRYe-AigFJZYlZoILQ1TjFPLByaAYaCz2-DQlKj7VIdGpji821UGRCVSBN4IA
shahhamdihassan commentedon Oct 25, 2026
Thanks for the report, and thanks @jorenham for pointing at typeshed. The related constructor bug (#4994) is now fixed on main. The invariance here comes from how the bundled typeshed stub declares frozendict's type parameters, so it's a typeshed question rather than a pyrefly one; we'll re-check it after our next stub update.
randolf-scholz commentedon Oct 26, 2026
@shahhamdihassan It seems though
frozendict(*{"a": 10})still goes through without error, I opened a new issue #5381 for thatshahhamdihassan commentedon Oct 27, 2026
We've now updated our bundled typeshed, and it still declares
frozendict's value type as invariant, so pyrefly will keep reporting this until typeshed changes it. Opening an issue on typeshed, as @jorenham suggested, is the best way to get that fixed, and pyrefly will pick it up with a later stub update.rchen152 commentedon Nov 5, 2026
@IIIMADDINIII Thanks for opening an issue with typeshed. Looks like the stub is now fixed, so this should be fixed the next time we update our bundled typeshed.
kinto0 commentedon Nov 25, 2026
working on a typeshed upgrade which will fix this