Attention!
Basedmypy supports this feature
Issue
m1: Mapping[str, object] = {"a": 1}
m2: Mapping[object, object] = m1 # error, lame
There are many many issues around about this
backwards compatibility assurance
there is a vary low chance of breaking edge cases of implementations of Mapping that abuse the invariant param:
from typing import *
class BadMap[K, V](Mapping[K, V]):
def __init__(self, key: K, value: V):
self.key: K
self.value: V
_secret_key: K
@override
def __getitem__(self, key: K) -> V:
"""you have to override a method method that takes `K` and make it do something unsafe like store the value"""
self._secret_value = key
return self.value
def get_key(self) -> K:
return self._secret_key
m: Mapping[str, object] = BadMap("key", "value")
b: Mapping[object, object] = m
b[2]
m.get_value() # revealed str, actually 2
I believe that this would be extremely rare in real life.
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog :^)
Attention!
Basedmypy supports this feature
Issue
There are many many issues around about this
backwards compatibility assurance
there is a vary low chance of breaking edge cases of implementations of
Mappingthat abuse the invariant param:I believe that this would be extremely rare in real life.
Upvote & Fund