Skip to content

Commit afd474d

Browse files
hive-botclaude
andcommitted
revert: send formality strings unchanged
This reverts commit 2883db6. The API rejects upper-case formality values, so lower-casing a formality string keeps calls such as formality="LESS" working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 71712b1 commit afd474d

4 files changed

Lines changed: 2 additions & 13 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
186186
wrap upload failures in `DocumentTranslationException`, with
187187
`document_handle` set to `None` and the original exception as `__cause__`.
188188
Invalid arguments still raise `ValueError` or `TypeError`.
189-
- `formality` is sent as given: a string such as `"Prefer_Less"` is no longer
190-
lower-cased before it is sent. `Formality` members send the same values as
191-
before.
192189

193190
### Deprecated
194191
- `Translator` is deprecated in favour of `DeepLClient`, which supports all its

‎README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ arguments are:
177177
[Listing available languages](#listing-available-languages).
178178
- `'less'` (`Formality.LESS`): use informal language.
179179
- `'more'` (`Formality.MORE`): use formal, more polite language.
180-
A string is sent unchanged, so pass the API's lower-case values.
181180
- `glossary`: specifies a glossary to use with translation, either as a string
182181
containing the glossary ID, or a `GlossaryInfo` as returned by
183182
`get_glossary()`.

‎deepl/translator.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def _check_language_and_formality(
274274
if source_lang is not None:
275275
request_data["source_lang"] = source_lang
276276
if formality is not None:
277-
request_data["formality"] = str(formality)
277+
request_data["formality"] = str(formality).lower()
278278
if isinstance(glossary, GlossaryInfo) or isinstance(
279279
glossary, MultilingualGlossaryInfo
280280
):

‎tests/offline/test_translate_text.py‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_sends_text_and_target_language(mocked):
116116
({"preserve_formatting": True}, {"preserve_formatting": True}),
117117
({"preserve_formatting": False}, {"preserve_formatting": False}),
118118
({"formality": deepl.Formality.MORE}, {"formality": "more"}),
119+
({"formality": "Prefer_Less"}, {"formality": "prefer_less"}),
119120
(
120121
{"tag_handling": "xml", "tag_handling_version": "v2"},
121122
{"tag_handling": "xml", "tag_handling_version": "v2"},
@@ -430,14 +431,6 @@ def test_returns_list_for_single_item_list(mocked):
430431
assert isinstance(results, list)
431432

432433

433-
def test_sends_formality_string_unchanged(mocked):
434-
reply_with_translation(mocked, {**BASE_BODY, "formality": "Prefer_Less"})
435-
436-
make_translator().translate_text(
437-
"hello", target_lang="DE", formality="Prefer_Less"
438-
)
439-
440-
441434
def test_warns_that_translate_text_with_glossary_is_deprecated(mocked):
442435
reply_with_translation(
443436
mocked,

0 commit comments

Comments
 (0)