build.dsl: allow both str and int resource attributes.

This commit is contained in:
whitequark 2019-08-30 08:35:52 +00:00
parent 98278a044d
commit a4b58cbf3a
2 changed files with 10 additions and 11 deletions

View file

@ -92,8 +92,9 @@ def DiffPairsN(*args, **kwargs):
class Attrs(OrderedDict):
def __init__(self, **attrs):
for key, value in attrs.items():
if not (value is None or isinstance(value, str) or hasattr(value, "__call__")):
raise TypeError("Value of attribute {} must be None, str, or callable, not {!r}"
if not (value is None or isinstance(value, (str, int)) or hasattr(value, "__call__")):
raise TypeError("Value of attribute {} must be None, int, str, or callable, "
"not {!r}"
.format(key, value))
super().__init__(**attrs)
@ -103,10 +104,8 @@ class Attrs(OrderedDict):
for key, value in self.items():
if value is None:
items.append("!" + key)
elif hasattr(value, "__call__"):
items.append(key + "=" + repr(value))
else:
items.append(key + "=" + value)
items.append(key + "=" + repr(value))
return "(attrs {})".format(" ".join(items))