In the typing of the translate_text it would be better to use method overloading, so that the return type is not ambiguous when passing a text variable that is either str or Iterable[str]
If typed like this mypy understands that when text is a str the return type is TextResult and when it is an Iterable[str] the return type is List[TextResult], avoiding error messages like when passing an Iterable[str] as text:
<file>:102: error: Item "TextResult" of "TextResult | list[TextResult]" has no attribute "__iter__" (not iterable) [union-attr]
In the typing of the translate_text it would be better to use method overloading, so that the return type is not ambiguous when passing a
text
variable that is eitherstr
orIterable[str]
So I suggest that here https://github.com/DeepLcom/deepl-python/blob/16108b0b4b196a67e8d5168490098dd96b312efe/deepl/translator.py#L334-L350 the typing should be something like:
If typed like this mypy understands that when text is a
str
the return type isTextResult
and when it is anIterable[str]
the return type isList[TextResult]
, avoiding error messages like when passing anIterable[str]
astext
:If you prefer, I'd be glad submit a pull request