From 178399da735a59bcfb7eba96963b58ad49bb0e3a Mon Sep 17 00:00:00 2001 From: Jan Ebbing Date: Wed, 8 Nov 2023 14:59:52 +0000 Subject: [PATCH] ci: Add mypy checking to pipeline --- .gitlab-ci.yml | 2 ++ CHANGELOG.md | 4 ++++ deepl/__init__.py | 27 +++++++++++++++++++++++++++ examples/basic_usage/__main__.py | 18 +++++++++++------- examples/basic_usage/mypy.ini | 2 ++ 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 examples/basic_usage/mypy.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cb72758..51d4f0e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -249,6 +249,8 @@ mustache_example_manual: - set -o pipefail - python . 2>&1 | tee basic_usage_result.txt - grep -q "Success" basic_usage_result.txt + - pip install mypy + - mypy . basic_usage_example_scheduled: extends: .basic_usage_example_base diff --git a/CHANGELOG.md b/CHANGELOG.md index 702e532..660dc6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added * Added basic usage example of the library +### Fixed +* Fixed typechecking errors when using `mypy`'s `strict` mode + * Thanks to [derlikh-smart](https://github.com/derlikh-smart) and [vad](https://github.com/vad) + for the report in [#82](https://github.com/DeepLcom/deepl-python/issues/82) ## [1.16.1] - 2023-11-07 diff --git a/deepl/__init__.py b/deepl/__init__.py index ab45fe1..1872e1e 100644 --- a/deepl/__init__.py +++ b/deepl/__init__.py @@ -37,3 +37,30 @@ convert_dict_to_tsv, validate_glossary_term, ) + +__all__ = [ + "__version__", + "__author__", + "DocumentHandle", + "DocumentStatus", + "Formality", + "GlossaryInfo", + "Language", + "SplitSentences", + "TextResult", + "Translator", + "Usage", + "http_client", + "AuthorizationException", + "ConnectionException", + "DeepLException", + "DocumentNotReadyException", + "DocumentTranslationException", + "GlossaryNotFoundException", + "TooManyRequestsException", + "QuotaExceededException", + "auth_key_is_free_account", + "convert_tsv_to_dict", + "convert_dict_to_tsv", + "validate_glossary_term", +] diff --git a/examples/basic_usage/__main__.py b/examples/basic_usage/__main__.py index b4ef314..1e18b4e 100644 --- a/examples/basic_usage/__main__.py +++ b/examples/basic_usage/__main__.py @@ -10,7 +10,7 @@ env_server_url = "DEEPL_SERVER_URL" -def main(): +def main() -> None: auth_key = os.getenv(env_auth_key) server_url = os.getenv(env_server_url) if auth_key is None: @@ -20,22 +20,25 @@ def main(): ) # Create a Translator object, and call get_usage() to validate connection - translator = deepl.Translator(auth_key, server_url=server_url) - translator.get_usage() + translator: deepl.Translator = deepl.Translator( + auth_key, server_url=server_url + ) + u: deepl.Usage = translator.get_usage() + u.any_limit_exceeded # Use most translation features of the library - translator.translate_text( + _ = translator.translate_text( ["I am an example sentence", "I am another sentence"], source_lang="EN", target_lang="FR", formality=deepl.Formality.DEFAULT, tag_handling=None, ) - ginfo = translator.create_glossary( + ginfo: deepl.GlossaryInfo = translator.create_glossary( "Test Glossary", "DE", "FR", {"Hallo": "Bonjour"} ) with io.BytesIO() as output_file: - translator.translate_document( + doc_status: deepl.DocumentStatus = translator.translate_document( "My example document", output_file, source_lang="DE", @@ -43,7 +46,8 @@ def main(): filename="example.txt", glossary=ginfo, ) - translator.translate_text_with_glossary( + doc_status.done + _ = translator.translate_text_with_glossary( ["Ich bin ein Beispielsatz.", "Ich bin noch ein Satz."], glossary=ginfo ) diff --git a/examples/basic_usage/mypy.ini b/examples/basic_usage/mypy.ini new file mode 100644 index 0000000..be0671c --- /dev/null +++ b/examples/basic_usage/mypy.ini @@ -0,0 +1,2 @@ +[mypy] +strict = true