Skip to content

Commit

Permalink
Stop “caching” prop names
Browse files Browse the repository at this point in the history
Fixes #162
  • Loading branch information
michael-k authored and markpeek committed Sep 27, 2021
1 parent 179cb19 commit 037b13a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions awacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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]
Expand Down

0 comments on commit 037b13a

Please sign in to comment.