basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

`TypedDict` should extend `dict` not `Mapping`

Open KotlinIsland opened this issue 2 years ago • 1 comments

And it should override the clear method to be Never.

KotlinIsland avatar Apr 07 '24 14:04 KotlinIsland

the only way to do this without breaking the functionality that bans clear from being called on TypedDicts would be to override its clear method with clear: Never, but that wouldn't work because pyright doesn't complain when you use objects typed as Never

so this change relies on #97

DetachHead avatar Apr 07 '24 14:04 DetachHead

this would also make reportInvalidCast less annoying (see here)

DetachHead avatar Jun 13 '24 10:06 DetachHead

eh, i don't think we should do this, it becomes less safe even if we make clear typed as Never:

foo: dict[{"a": int}]

bar: dict[str, int] = foo

bar.clear() # no error

DetachHead avatar Jul 11 '24 09:07 DetachHead

Is this only because we don't get an error about unreachable?

KotlinIsland avatar Jul 11 '24 12:07 KotlinIsland

no it's because the Never is widened to something that's not Never

DetachHead avatar Jul 11 '24 12:07 DetachHead