From a025ea50ad860d20b09b4ca55c85bfcdf5a2049b Mon Sep 17 00:00:00 2001 From: Andrew Srg Date: Thu, 1 Feb 2024 22:38:15 +0200 Subject: [PATCH] refactor literal loader with single enum, edit documentation --- docs/loading-and-dumping/specific-types-behavior.rst | 2 +- src/adaptix/_internal/morphing/generic_provider.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/loading-and-dumping/specific-types-behavior.rst b/docs/loading-and-dumping/specific-types-behavior.rst index 40646a8b..130729fc 100644 --- a/docs/loading-and-dumping/specific-types-behavior.rst +++ b/docs/loading-and-dumping/specific-types-behavior.rst @@ -148,7 +148,7 @@ Literal Loader accepts only values listed in ``Literal``. If ``strict_coercion`` is enabled, the loader will distinguish equal ``bool`` and ``int`` instances, otherwise, they will be considered as same values. -``Enum`` instances will be loaded via its loaders, which have a higher priority over others values, that is, they will be applied first. +``Enum`` instances will be loaded via its loaders. Enum loaders have a higher priority over others, that is, they will be applied first. If the input value could be interpreted as several ``Literal`` members, the result will be undefined. diff --git a/src/adaptix/_internal/morphing/generic_provider.py b/src/adaptix/_internal/morphing/generic_provider.py index cc750dae..934b5278 100644 --- a/src/adaptix/_internal/morphing/generic_provider.py +++ b/src/adaptix/_internal/morphing/generic_provider.py @@ -160,9 +160,11 @@ def _get_literal_loader_with_enum( # noqa: CCR001 return basic_loader if len(enum_loaders) == 1: + enum_loader = enum_loaders[0] + def wrapped_loader_with_single_enum(data): try: - enum_value = enum_loaders[0](data) + enum_value = enum_loader(data) except LoadError: pass else: