From 91e713a2a468faa882e8c7d9fbbadb2cdc727e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=BDubom=C3=ADr=20Gallovi=C4=8D?= Date: Thu, 5 Jan 2023 10:23:28 +0100 Subject: [PATCH] Make pushsource compatible with attrs version 22.2.0 Since new attrs version release, pub tests have begun failing with the error "TypeError: keywords must be strings". Attrs have added an "alias" parameter to each attribute[1], which is used in the attrs's "evolve" method to construct a new instance. This causes issues with the attribute "from", which has some special logic implemented in order to be usable at all[2]. The attribute "from" is generated from "from_", copying all its parameters. Since "alias" is a new parameter, it isn't copied and thus its value is set no "None". attrs's "evolve" method uses **kwargs to create a new instance, and it sets one of the keys in **kwargs to "None" (from alias). Keys in **kwargs must be strings, which causes the TypeError. It can be fixed by also setting "alias" in the newly created "from" attribute. In case of "from_", it has the same value as "name" parameter ("from_"), which is why we don't want to copy it from the old attribute, but explicitly set it to "from" (otherwise it would be "from_"). The change should be backwards compatible with older versions of attrs. [1] https://github.com/python-attrs/attrs/pull/950 [2] https://github.com/release-engineering/pushsource/pull/108 --- src/pushsource/_impl/model/erratum_fixup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pushsource/_impl/model/erratum_fixup.py b/src/pushsource/_impl/model/erratum_fixup.py index bc84deed..80d028a6 100644 --- a/src/pushsource/_impl/model/erratum_fixup.py +++ b/src/pushsource/_impl/model/erratum_fixup.py @@ -53,6 +53,8 @@ def __init__(self, delegate, attrs_old_to_new): # (we do this dynamically to cope with differences between ancient and newer # versions of attrs library) attr_kwargs = {"name": new_name} + if hasattr(old_attr, "alias"): + attr_kwargs["alias"] = new_name for argname in [ "default", "validator",