id_translation.translator_typing#

Types that are specific to the 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().

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().

fmt#
class ExtractNamesParams[source]#

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

Arguments of Translator.extract_names().

ignore_names#
io_kwargs#
raising#
translatable#
class FetchParams[source]#

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

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

fmt#
ignore_names#
io_kwargs#
max_fails#
names#
override_function#
translatable#
FetcherTypes = id_translation.offline._translation_map.TranslationMap[~NameType, ~SourceType, ~IdType] | id_translation.fetching._fetcher.Fetcher[~SourceType, ~IdType] | dict[~SourceType, id_translation.offline.types.PlaceholderTranslations[~SourceType]] | dict[~SourceType, dict[~IdType, str]] | collections.abc.Mapping[~SourceType, id_translation.offline.types.PlaceholderTranslations[~SourceType] | ForwardRef('pandas.DataFrame') | typing.Mapping[str, collections.abc.Sequence[typing.Any]] | typing.Mapping[~IdType, str]]#

All valid input types for creating a Translator.

class MapParams[source]#

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

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

ignore_names#
io_kwargs#
names#
override_function#
translatable#
NativeFetcherTypes = id_translation.offline._translation_map.TranslationMap[~NameType, ~SourceType, ~IdType] | id_translation.fetching._fetcher.Fetcher[~SourceType, ~IdType] | dict[~SourceType, id_translation.offline.types.PlaceholderTranslations[~SourceType]]#

Internal types related to fetching.

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#
io_kwargs#
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#