Closed
Description
Bug Report
Recursive generic code has broken inference
from typing import TypeVar, List, Dict, Any
V = TypeVar("V", List[Any], Dict[Any, Any], float, int, str, bool)
def normalize_keys(value: V) -> V:
if isinstance(value, list):
return [normalize_keys(v) for v in value]
elif isinstance(value, dict):
return {_normalize_key(k): normalize_keys(v) for k, v in value.items()}
else:
return value
def _normalize_key(key: str) -> str:
return key.lower().strip("_").replace(".", "_")
To Reproduce
Expected Behavior
It should pass as this is valid code.
It passes in mypy 0.971, but reports error in mypy 0.981 and 0.982.
Actual Behavior
Throws error
main.py:10: error: Incompatible return value type (got "Dict[str, Any]", expected "float")
Your Environment
see the sandbox