Skip to content

Commit 61d9d2d

Browse files
hive-botclaude
andcommitted
fix: keep the released type of multilingual glossary entries
MultilingualGlossaryDictionaryEntries.entries keeps its released Dict[str, str] annotation and caller-built entries are always converted to TSV. The TSV string read from the API is passed through a cast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c8a2306 commit 61d9d2d

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎deepl/api_data.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55
import datetime
66
from enum import Enum, auto
7-
from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union
7+
from typing import (
8+
Any,
9+
Dict,
10+
List,
11+
NamedTuple,
12+
Optional,
13+
Tuple,
14+
Union,
15+
cast,
16+
)
817

918
from deepl.util import (
1019
get_float_safe,
@@ -710,7 +719,7 @@ def __init__(
710719
self,
711720
source_lang: str,
712721
target_lang: str,
713-
entries: Union[str, Dict[str, str]],
722+
entries: Dict[str, str],
714723
):
715724
self._source_lang = source_lang
716725
self._target_lang = target_lang
@@ -737,7 +746,8 @@ def from_json(json) -> "MultilingualGlossaryDictionaryEntries":
737746
return MultilingualGlossaryDictionaryEntries(
738747
str(json["source_lang"]),
739748
str(json["target_lang"]),
740-
entries,
749+
# Released behaviour: API entries stay the raw TSV string.
750+
cast(Dict[str, str], entries),
741751
)
742752
except (KeyError, TypeError, ValueError) as error:
743753
raise _malformed_response(
@@ -763,9 +773,7 @@ def target_lang(self) -> str:
763773
return self._target_lang
764774

765775
@property
766-
def entries(self) -> Union[str, Dict[str, str]]:
767-
"""Returns the entries: a dictionary of source-target terms, or the
768-
TSV string as returned by the API."""
776+
def entries(self) -> Dict[str, str]:
769777
return self._entries
770778

771779

‎deepl/deepl_client.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def _replace_multilingual_glossary_dictionary(
759759
glossary: Union[str, MultilingualGlossaryInfo],
760760
source_lang: str,
761761
target_lang: str,
762-
entries: Union[str, Dict[str, str]],
762+
entries: Dict[str, str],
763763
extra_body_parameters: Optional[dict],
764764
) -> MultilingualGlossaryDictionaryInfo:
765765
glossary_id = self._multilingual_glossary_id(glossary)
@@ -1002,11 +1002,7 @@ def _dictionary_json(
10021002
"target_lang": Language.remove_regional_variant(
10031003
dictionary.target_lang
10041004
),
1005-
"entries": (
1006-
dictionary.entries
1007-
if isinstance(dictionary.entries, str)
1008-
else util.convert_dict_to_tsv(dictionary.entries)
1009-
),
1005+
"entries": util.convert_dict_to_tsv(dictionary.entries),
10101006
"entries_format": "tsv",
10111007
}
10121008

0 commit comments

Comments
 (0)