Skip to content

Commit

Permalink
refactor literal loader with single enum, edit documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
andiserg committed Feb 1, 2024
1 parent 524f931 commit a025ea5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/loading-and-dumping/specific-types-behavior.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion src/adaptix/_internal/morphing/generic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a025ea5

Please sign in to comment.