Add typing hints to CaseInsensitiveDict, fix it's __setitem__ signature, call

.items() on `other` in ctor
This commit is contained in:
jesopo 2018-12-08 09:13:01 +00:00
parent 8cc1168589
commit 1c546a8244

View file

@ -173,9 +173,9 @@ def top_10(items: typing.Dict[typing.Any, typing.Any],
return top_10_items return top_10_items
class CaseInsensitiveDict(dict): class CaseInsensitiveDict(dict):
def __init__(self, other): def __init__(self, other: typing.Dict[str, typing.Any]):
dict.__init__(self, ((k.lower(), v) for k, v in other)) dict.__init__(self, ((k.lower(), v) for k, v in other.items()))
def __getitem__(self, key): def __getitem__(self, key: str) -> typing.Any:
return dict.__getitem__(self, key.lower()) return dict.__getitem__(self, key.lower())
def __setitem__(self, key): def __setitem__(self, key: str, value: typing.Any) -> typing.Any:
return dict.__setitem__(self, key.lower()) return dict.__setitem__(self, key.lower(), value)