Skip to content

Commit

Permalink
[Core] Update typing annotations for CaseInsensitive Dictionary (#25537)
Browse files Browse the repository at this point in the history
* update typing annotations

* change type

* typing fix

* fix type

* line too long pylint
  • Loading branch information
kashifkhan authored Aug 4, 2022
1 parent e789c73 commit 9e13f97
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sdk/core/azure-core/azure/core/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# license information.
# --------------------------------------------------------------------------
import datetime
from typing import Any, Dict, Iterator, Mapping, MutableMapping
from typing import Any, Dict, Iterable, Iterator, Mapping, MutableMapping, Optional, Tuple, Union


class _FixedOffset(datetime.tzinfo):
Expand Down Expand Up @@ -89,7 +89,7 @@ def case_insensitive_dict(*args: Any, **kwargs: Any) -> MutableMapping:
"""
return CaseInsensitiveDict(*args, **kwargs)

class CaseInsensitiveDict(MutableMapping):
class CaseInsensitiveDict(MutableMapping[str, Any]):
"""
NOTE: This implementation is heavily inspired from the case insensitive dictionary from the requests library.
Thank you !!
Expand All @@ -100,7 +100,11 @@ class CaseInsensitiveDict(MutableMapping):
case_insensitive_dict['key'] == 'some_value' #True
"""

def __init__(self, data=None, **kwargs: Any) -> None:
def __init__(
self,
data: Optional[Union[Mapping[str, Any], Iterable[Tuple[str, Any]]]] = None,
**kwargs: Any
) -> None:
self._store: Dict[str, Any] = {}
if data is None:
data = {}
Expand All @@ -110,7 +114,7 @@ def __init__(self, data=None, **kwargs: Any) -> None:
def copy(self) -> "CaseInsensitiveDict":
return CaseInsensitiveDict(self._store.values())

def __setitem__(self, key: str, value: str) -> None:
def __setitem__(self, key: str, value: Any) -> None:
"""
Set the `key` to `value`. The original key will be stored with the value
"""
Expand All @@ -122,7 +126,7 @@ def __getitem__(self, key: str) -> Any:
def __delitem__(self, key: str) -> None:
del self._store[key.lower()]

def __iter__(self) -> Iterator[Any]:
def __iter__(self) -> Iterator[str]:
return (key for key, _ in self._store.values())

def __len__(self) -> int:
Expand Down

0 comments on commit 9e13f97

Please sign in to comment.