id_translation.dio.default#

Default DataStructureIO implementations.

Classes

DictIO()

IO implementation for dict types.

SequenceIO()

IO implementation for list, tuple and numpy.array types.

SetIO()

IO implementation for set types.

SingleValueIO()

IO implementation for int, str and UUID types.

class DictIO[source]#

Bases: DataStructureIO[dict[NameType, IdType], NameType, SourceType, IdType]

IO implementation for dict types.

classmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

classmethod insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

classmethod names(translatable)[source]#

Extract names from translatable.

Parameters:

translatable – Data to extract names from.

Returns:

A list of names to translate. Returns None if names cannot be extracted.

priority = 1000#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.

class SequenceIO[source]#

Bases: DataStructureIO[SequenceT, NameType, SourceType, IdType]

IO implementation for list, tuple and numpy.array types.

class SequenceT#

alias of TypeVar(‘SequenceT’, list, ~numpy.ndarray, tuple)

classmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

classmethod insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

priority = 1100#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.

class SetIO[source]#

Bases: DataStructureIO[set[IdType], NameType, SourceType, IdType]

IO implementation for set types.

classmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

classmethod insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

priority = 1010#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.

class SingleValueIO[source]#

Bases: DataStructureIO[IdType, NameType, SourceType, IdType]

IO implementation for int, str and UUID types.

classmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

classmethod insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

priority = 1500#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.