Whole file

anikolaienko/py-automapper

The author described this change as Fix mapping of string enum types. It counts as a record because the check below fails on the code as it stood at 01c250840 and passes on e658a3d43, with nothing else changed between the two runs.

Fix saved2022-11-20
Sharing licenceMIT · LICENSE
Change size+7 1

What the code was meant to do, written into the code itself as a save note

Fix mapping of string enum types

The change

11 import inspect
22 from copy import deepcopy
3+from enum import Enum
34 from typing import (
45 Any,
56 Callable,
5152 return type(obj) in __PRIMITIVE_TYPES
5253
5354
55+def _is_enum(obj: Any) -> bool:
56+ """Check if object type is enum"""
57+ return issubclass(type(obj), Enum)
58+
59+
5460 def _try_get_field_value(
5561 field_name: str, original_obj: Any, custom_mapping: FieldsMap
5662 ) -> Tuple[bool, Any]:
267273 self, obj: S, _visited_stack: Set[int], skip_none_values: bool = False
268274 ) -> Any:
269275 """Maps subobjects recursively"""
270- if _is_primitive(obj):
276+ if _is_primitive(obj) or _is_enum(obj):
271277 return obj
272278
273279 obj_id = id(obj)

The check that tells the two apart

failpass·tests/test_automapper_enum.py::test_map__enum

Check file tests/test_automapper_enum.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it01c250840d4cb584582f203f75fabdecbaedfa03
Broken version dated2022-11-13
Moduleautomapper.mapper
Units changedMapper
Fingerprint7738ef352132fb26
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.