id_translation.translator_typing#

Types that are specific to the id_translation.Translator implementation.

Module Attributes

SimpleDictFetcherTypes

Data for translating using only the default id and name placeholders.

SourceToPlaceholderTranslationsMakeTypes

Data for translating using arbitrary placeholders; see PlaceholderTranslations.make()

NativeFetcherTypes

Internal types related to fetching.

FetcherTypes

All valid input types for creating a Translator.

CacheMissReasonType

High-level reason why a cached Translator was rejected.

Classes

class AbstractFetcherParams[source]#

Bases: TypedDict, Generic[SourceType, IdType]

Keyword arguments for the AbstractFetcher base class.

allow_fetch_all#
cache_access#
identifiers#
mapper#
optional#
selective_fetch_all#
class AllTranslateParams[source]#

Bases: TranslateParams[NameType, SourceType, IdType]

All arguments of Translator.translate().

fmt#
ignore_names#
max_fails#
names#
override_function#
reverse#
translatable#
CacheMissReasonType#

High-level reason why a cached Translator was rejected.

alias of Literal[‘metadata-missing’, ‘metadata-changed’, ‘too-old’]

class CopyParams[source]#

Bases: UniqueCopyParams[NameType, SourceType, IdType]

All arguments of Translator.copy().

default_fmt#
default_fmt_placeholders#
enable_uuid_heuristics#
fetcher#
fmt#
mapper#
transformers#
class FetchParams[source]#

Bases: TypedDict, Generic[NameType, SourceType, IdType]

All arguments of Translator.fetch() and Translator.go_offline().

fmt#
ignore_names#
names#
override_function#
translatable#
FetcherTypes#

All valid input types for creating a Translator.

alias of TranslationMap[NameType, SourceType, IdType] | Fetcher[SourceType, IdType] | dict[SourceType, PlaceholderTranslations[SourceType]] | dict[SourceType, dict[IdType, str]] | Mapping[SourceType, PlaceholderTranslations[SourceType] | pandas.DataFrame | Mapping[str, Sequence[Any]] | Mapping[IdType, str]]

class MapParams[source]#

Bases: TypedDict, Generic[NameType, SourceType, IdType]

Arguments of Translator.map() and Translator.map_scores().

ignore_names#
names#
override_function#
translatable#
NativeFetcherTypes#

Internal types related to fetching.

alias of TranslationMap[NameType, SourceType, IdType] | Fetcher[SourceType, IdType] | dict[SourceType, PlaceholderTranslations[SourceType]]

SimpleDictFetcherTypes#

Data for translating using only the default id and name placeholders.

Must be on the form {source: {id: name}}.

alias of dict[SourceType, dict[IdType, str]]

SourceToPlaceholderTranslationsMakeTypes#

Data for translating using arbitrary placeholders; see PlaceholderTranslations.make()

alias of Mapping[SourceType, PlaceholderTranslations[SourceType] | pandas.DataFrame | Mapping[str, Sequence[Any]] | Mapping[IdType, str]]

class TranslateParams[source]#

Bases: TypedDict, Generic[NameType, SourceType, IdType]

Keyword arguments of Translator.translate().

Note

Does not include translatable or copy.

Motivation

Allowing these to be passed as keyword arguments causes issues with typing, especially method overloading. For example:

def func(**kwargs: Unpack[AllTranslateParams]):
   translatable = kwargs["translatable"]
   if isinstance(translatable, list) and kwargs.get(copy, True):
       raise CustomException("we don't do that here")

   else:
       # Do whatever

using AllTranslateParams is typically not as safe as:

@overload
def func(...): ...

@overload
def func(
    translatable: list, copy: Literal[False],
    **kwargs: Unpack[TranslateParams]
) -> Never: ...

def func(translatable, copy, **kwargs: Unpack[TranslateParams]):
    "Implementation as above"

since func(translatable=[], copy=False) does not behave like Translator.translate([], copy=False) would. Functions that transparently wrap Translator.translate() should probably use functools.wraps() instead.

fmt#
ignore_names#
max_fails#
names#
override_function#
reverse#
class UniqueCopyParams[source]#

Bases: TypedDict, Generic[NameType, SourceType, IdType]

Arguments of Translator.copy() that do not overlap with AllTranslateParams.

default_fmt#
default_fmt_placeholders#
enable_uuid_heuristics#
fetcher#
mapper#
transformers#