Description
Describe the bug
Hello!
The translate
function returns a Dict[str, Any]
.
When using the result of a translation, I want to read the loc
attribute.
Eg: error.get("loc")
But it leads to a Mypy error: Value of type "Optional[Any]" is not indexable
.
To correct this, I use the ErrorDict
type included in the pydantic lib, to improve type checking. If we look at the pydantic source code, we get:
Loc = Tuple[Union[int, str], ...]
class _ErrorDictRequired(TypedDict):
loc: Loc
msg: str
type: str
class ErrorDict(_ErrorDictRequired, total=False):
ctx: Dict[str, Any]
which is an equivalent of:
class ErrorDict(TypedDict, total=False):
loc: Loc
msg: str
type: str
ctx: Dict[str, Any]
Proposal
Instead of returning a Dict[str, Any]
, the translate
function should return a pydantic ErrorDict
.
Environment
- OS: Linux Ubuntu 22.04
- pydantic-i18n version: 0.3.0
- Python version: 3.10