From bb4383c2d97aae0e8a01db64f142d07350861a17 Mon Sep 17 00:00:00 2001 From: Tin Tvrtkovic Date: Sat, 18 Dec 2021 15:21:20 +0100 Subject: [PATCH] Remove walrus --- src/cattr/preconf/bson.py | 5 ++--- src/cattr/preconf/orjson.py | 7 ++----- src/cattr/preconf/tomlkit.py | 5 ++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/cattr/preconf/bson.py b/src/cattr/preconf/bson.py index 994b6714..78ef55cc 100644 --- a/src/cattr/preconf/bson.py +++ b/src/cattr/preconf/bson.py @@ -17,9 +17,8 @@ def configure_converter(converter: GenConverter): def gen_unstructure_mapping(cl: Any, unstructure_to=None): key_handler = str - if (args := getattr(cl, "__args__", None)) and issubclass( - args[0], str - ): + args = getattr(cl, "__args__", None) + if args and issubclass(args[0], str): key_handler = None return converter.gen_unstructure_mapping( cl, unstructure_to=unstructure_to, key_handler=key_handler diff --git a/src/cattr/preconf/orjson.py b/src/cattr/preconf/orjson.py index 1c39ae95..31c451c0 100644 --- a/src/cattr/preconf/orjson.py +++ b/src/cattr/preconf/orjson.py @@ -30,11 +30,8 @@ def configure_converter(converter: GenConverter): def gen_unstructure_mapping(cl: Any, unstructure_to=None): key_handler = str - if ( - (args := getattr(cl, "__args__", None)) - and issubclass(args[0], str) - and issubclass(args[0], Enum) - ): + args = getattr(cl, "__args__", None) + if args and issubclass(args[0], str) and issubclass(args[0], Enum): def key_handler(v): return v.value diff --git a/src/cattr/preconf/tomlkit.py b/src/cattr/preconf/tomlkit.py index cdc652d7..b1153140 100644 --- a/src/cattr/preconf/tomlkit.py +++ b/src/cattr/preconf/tomlkit.py @@ -24,9 +24,8 @@ def configure_converter(converter: GenConverter): def gen_unstructure_mapping(cl: Any, unstructure_to=None): key_handler = str - if (args := getattr(cl, "__args__", None)) and issubclass( - args[0], str - ): + args = getattr(cl, "__args__", None) + if args and issubclass(args[0], str): key_handler = None return converter.gen_unstructure_mapping( cl, unstructure_to=unstructure_to, key_handler=key_handler