Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7445ab6

Browse files
committed
Move cloudformation attribute setting to __setattr__
Move the cloudformation attribute setting into __setattr__ so the attributes (like Metadata) can be set after object initialization.
1 parent c48dd96 commit 7445ab6

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

troposphere/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,11 @@ def __init__(self, title, template=None, **kwargs):
5959
for k, (_, required) in self.props.items():
6060
v = getattr(type(self), k, None)
6161
if v is not None and k not in kwargs:
62-
if k in self.attributes:
63-
self.resource[k] = v
64-
else:
65-
self.__setattr__(k, v)
62+
self.__setattr__(k, v)
6663

6764
# Now that it is initialized, populate it with the kwargs
6865
for k, v in kwargs.items():
69-
# Special case Resource Attributes
70-
if k in self.attributes:
71-
self.resource[k] = v
72-
else:
73-
self.__setattr__(k, v)
66+
self.__setattr__(k, v)
7467

7568
# Bound it to template if we know it
7669
if self.template is not None:
@@ -91,6 +84,9 @@ def __setattr__(self, name, value):
9184
if name in self.__dict__.keys() \
9285
or '_BaseAWSObject__initialized' not in self.__dict__:
9386
return dict.__setattr__(self, name, value)
87+
elif name in self.attributes:
88+
self.resource[name] = value
89+
return None
9490
elif name in self.propnames:
9591
# Check the type of the object and compare against what we were
9692
# expecting.

0 commit comments

Comments
 (0)