From d3556c43a500620bf2b743f07124dca215966339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Wed, 22 Sep 2021 10:13:00 +0200 Subject: [PATCH] =?UTF-8?q?Stop=20=E2=80=9Ccaching=E2=80=9D=20prop=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes cloudtools/awacs#162 --- awacs/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/awacs/__init__.py b/awacs/__init__.py index 2da72b2b..ac99f7f2 100644 --- a/awacs/__init__.py +++ b/awacs/__init__.py @@ -7,7 +7,7 @@ import json import re import types -from typing import Any, NoReturn, Optional, TypeVar, Union +from typing import Any, KeysView, NoReturn, Optional, TypeVar, Union __version__ = "2.0.1" @@ -25,8 +25,6 @@ def __init__( ) -> None: self.name = name self.props = props or {} - # Cache the keys for validity checks - self.propnames = self.props.keys() # unset/None is also legal if name and not valid_names.match(name): @@ -46,6 +44,11 @@ def __init__( for k, v in kwargs.items(): self.__setattr__(k, v) + @property + def propnames(self) -> KeysView[str]: + # For backwards compatibility; should be removed in v3 + return self.props.keys() + def __getattr__(self, name: str) -> Any: try: return self.properties.__getitem__(name) @@ -55,7 +58,7 @@ def __getattr__(self, name: str) -> Any: def __setattr__(self, name: str, value: Any) -> Any: if "_AWSObject__initialized" not in self.__dict__: return dict.__setattr__(self, name, value) - elif name in self.propnames: + elif name in self.props: # Check the type of the object and compare against what we were # expecting. expected_type = self.props[name][0]