argos-translate
argos-translate copied to clipboard
Use type hints instead of type in annotations
maybe we could use the python type hints for typing rather than in docstrings? for argostranslate v2 maybe?
Exemple:
old:
def get_translation_from_codes(from_code, to_code):
"""Gets a translation object from codes for from and to languages
An exception will be thrown if an installed translation between the from lang
and to lang can not be found.
Args:
from_code (str): The ISO 639 code of the source language
to_code (str): The ISO 639 code of the target language
Returns:
translate.ITranslation: The translation object
"""
from_lang = get_language_from_code(from_code)
to_lang = get_language_from_code(to_code)
return from_lang.get_translation(to_lang)
new:
def get_translation_from_codes(from_code: str, to_code: str) -> ITranslation:
"""Gets a translation object from codes for from and to languages
An exception will be thrown if an installed translation between the from lang
and to lang can not be found.
Args:
from_code: The ISO 639 code of the source language
to_code: The ISO 639 code of the target language
Returns:
The translation object
"""
from_lang = get_language_from_code(from_code)
to_lang = get_language_from_code(to_code)
return from_lang.get_translation(to_lang)
Yes I think moving to type hints is a good idea. I think it will break Python versions earlier than 3.5 but that's fine. LibreTranslate already only supports >3.7.
This can go in the master
branch, it doesn't need to be in v2
.
I'm planning to work on this soon (but can still accept pull requests). I'm going to put it in the "v2" branch after all to avoid merge conflicts.