-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround methods for mypy type inference problems with converters
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from typing import Any, Iterable, Mapping, Optional, Tuple, Union | ||
|
||
from immutablecollections import ( | ||
ImmutableDict, | ||
ImmutableListMultiDict, | ||
ImmutableSet, | ||
ImmutableSetMultiDict, | ||
immutabledict, | ||
immutablelistmultidict, | ||
immutableset, | ||
immutablesetmultidict, | ||
) | ||
|
||
|
||
def _to_tuple(val: Iterable[Any]) -> Tuple[Any, ...]: | ||
"""Needed until https://github.com/python/mypy/issues/5738 | ||
and https://github.com/python-attrs/attrs/issues/519 are fixed. | ||
""" | ||
return tuple(val) | ||
|
||
|
||
def _to_immutableset(val: Optional[Iterable[Any]]) -> ImmutableSet[Any]: | ||
"""Needed until https://github.com/python/mypy/issues/5738 | ||
and https://github.com/python-attrs/attrs/issues/519 are fixed. | ||
""" | ||
return immutableset(val) | ||
|
||
|
||
def _to_immutabledict( | ||
val: Optional[ | ||
Union[Iterable[Tuple[Any, Any]], Mapping[Any, Any], ImmutableDict[Any, Any]] | ||
] | ||
) -> ImmutableDict[Any, Any]: | ||
"""Needed until https://github.com/python/mypy/issues/5738 | ||
and https://github.com/python-attrs/attrs/issues/519 are fixed. | ||
""" | ||
return immutabledict(val) | ||
|
||
|
||
def _to_immutablesetmultidict( | ||
val: Optional[ | ||
Union[ | ||
Iterable[Tuple[Any, Any]], Mapping[Any, Any], ImmutableSetMultiDict[Any, Any] | ||
] | ||
] | ||
) -> ImmutableSetMultiDict[Any, Any]: | ||
"""Needed until https://github.com/python/mypy/issues/5738 | ||
and https://github.com/python-attrs/attrs/issues/519 are fixed. | ||
""" | ||
return immutablesetmultidict(val) | ||
|
||
|
||
def _to_immutablelistmultidict( | ||
val: Optional[ | ||
Union[ | ||
Iterable[Tuple[Any, Any]], Mapping[Any, Any], ImmutableListMultiDict[Any, Any] | ||
] | ||
] | ||
) -> ImmutableListMultiDict[Any, Any]: | ||
"""Needed until https://github.com/python/mypy/issues/5738 | ||
and https://github.com/python-attrs/attrs/issues/519 are fixed. | ||
""" | ||
return immutablelistmultidict(val) |