Skip to content

Commit 178399d

Browse files
committed
ci: Add mypy checking to pipeline
1 parent 6580073 commit 178399d

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ mustache_example_manual:
249249
- set -o pipefail
250250
- python . 2>&1 | tee basic_usage_result.txt
251251
- grep -q "Success" basic_usage_result.txt
252+
- pip install mypy
253+
- mypy .
252254

253255
basic_usage_example_scheduled:
254256
extends: .basic_usage_example_base

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Added
1010
* Added basic usage example of the library
11+
### Fixed
12+
* Fixed typechecking errors when using `mypy`'s `strict` mode
13+
* Thanks to [derlikh-smart](https://github.com/derlikh-smart) and [vad](https://github.com/vad)
14+
for the report in [#82](https://github.com/DeepLcom/deepl-python/issues/82)
1115

1216

1317
## [1.16.1] - 2023-11-07

deepl/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,30 @@
3737
convert_dict_to_tsv,
3838
validate_glossary_term,
3939
)
40+
41+
__all__ = [
42+
"__version__",
43+
"__author__",
44+
"DocumentHandle",
45+
"DocumentStatus",
46+
"Formality",
47+
"GlossaryInfo",
48+
"Language",
49+
"SplitSentences",
50+
"TextResult",
51+
"Translator",
52+
"Usage",
53+
"http_client",
54+
"AuthorizationException",
55+
"ConnectionException",
56+
"DeepLException",
57+
"DocumentNotReadyException",
58+
"DocumentTranslationException",
59+
"GlossaryNotFoundException",
60+
"TooManyRequestsException",
61+
"QuotaExceededException",
62+
"auth_key_is_free_account",
63+
"convert_tsv_to_dict",
64+
"convert_dict_to_tsv",
65+
"validate_glossary_term",
66+
]

examples/basic_usage/__main__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
env_server_url = "DEEPL_SERVER_URL"
1111

1212

13-
def main():
13+
def main() -> None:
1414
auth_key = os.getenv(env_auth_key)
1515
server_url = os.getenv(env_server_url)
1616
if auth_key is None:
@@ -20,30 +20,34 @@ def main():
2020
)
2121

2222
# Create a Translator object, and call get_usage() to validate connection
23-
translator = deepl.Translator(auth_key, server_url=server_url)
24-
translator.get_usage()
23+
translator: deepl.Translator = deepl.Translator(
24+
auth_key, server_url=server_url
25+
)
26+
u: deepl.Usage = translator.get_usage()
27+
u.any_limit_exceeded
2528

2629
# Use most translation features of the library
27-
translator.translate_text(
30+
_ = translator.translate_text(
2831
["I am an example sentence", "I am another sentence"],
2932
source_lang="EN",
3033
target_lang="FR",
3134
formality=deepl.Formality.DEFAULT,
3235
tag_handling=None,
3336
)
34-
ginfo = translator.create_glossary(
37+
ginfo: deepl.GlossaryInfo = translator.create_glossary(
3538
"Test Glossary", "DE", "FR", {"Hallo": "Bonjour"}
3639
)
3740
with io.BytesIO() as output_file:
38-
translator.translate_document(
41+
doc_status: deepl.DocumentStatus = translator.translate_document(
3942
"My example document",
4043
output_file,
4144
source_lang="DE",
4245
target_lang="FR",
4346
filename="example.txt",
4447
glossary=ginfo,
4548
)
46-
translator.translate_text_with_glossary(
49+
doc_status.done
50+
_ = translator.translate_text_with_glossary(
4751
["Ich bin ein Beispielsatz.", "Ich bin noch ein Satz."], glossary=ginfo
4852
)
4953

examples/basic_usage/mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
strict = true

0 commit comments

Comments
 (0)