id_translation.translator_typing#
Types that are specific to the id_translation.Translator implementation.
Module Attributes
Data for translating using only the default id and name placeholders. |
|
Data for translating using arbitrary placeholders; see |
|
Internal types related to fetching. |
|
All valid input types for creating a |
|
High-level reason why a cached |
Classes
Keyword arguments for the |
|
All arguments of |
|
All arguments of |
|
All arguments of |
|
Arguments of |
|
Keyword arguments of |
|
Arguments of |
- class AbstractFetcherParams[source]#
Bases:
TypedDict,Generic[SourceType,IdType]Keyword arguments for the
AbstractFetcherbase 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
Translatorwas 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()andTranslator.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|dict[str,Sequence[Any]] |dict[IdType,str]]
- class MapParams[source]#
Bases:
TypedDict,Generic[NameType,SourceType,IdType]Arguments of
Translator.map()andTranslator.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|dict[str,Sequence[Any]] |dict[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
AllTranslateParamsis 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 likeTranslator.translate([], copy=False)would. Functions that transparently wrapTranslator.translate()should probably usefunctools.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 withAllTranslateParams.- default_fmt#
- default_fmt_placeholders#
- enable_uuid_heuristics#
- fetcher#
- mapper#
- transformers#