Skip to content

Commit

Permalink
ci: Add mypy checking to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
JanEbbing committed Nov 20, 2023
1 parent 6580073 commit 178399d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions deepl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
18 changes: 11 additions & 7 deletions examples/basic_usage/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,30 +20,34 @@ 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",
target_lang="FR",
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
)

Expand Down
2 changes: 2 additions & 0 deletions examples/basic_usage/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
strict = true

0 comments on commit 178399d

Please sign in to comment.