tools: fix PropertyAction
self.default={} is mutable, so instead of modifying value derived from that default, retrieve value, copy it and store again. Otherwise tests (where the same parser is used multiple times) fails badly. The same approach is used in argparse._AppendAction.
This commit is contained in:
parent
377a82105d
commit
984ea09cef
@ -71,7 +71,12 @@ class PropertyAction(argparse.Action):
|
||||
except ValueError:
|
||||
parser.error('invalid property token: {!r}'.format(values))
|
||||
|
||||
getattr(namespace, self.dest)[prop] = value
|
||||
properties = getattr(namespace, self.dest)
|
||||
# copy it, to not modify _mutable_ self.default
|
||||
if not properties:
|
||||
properties = properties.copy()
|
||||
properties[prop] = value
|
||||
setattr(namespace, self.dest, properties)
|
||||
|
||||
|
||||
class SinglePropertyAction(argparse.Action):
|
||||
@ -102,8 +107,13 @@ class SinglePropertyAction(argparse.Action):
|
||||
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
getattr(namespace, self.dest)[self.name] = values \
|
||||
properties = getattr(namespace, self.dest)
|
||||
# copy it, to not modify _mutable_ self.default
|
||||
if not properties:
|
||||
properties = properties.copy()
|
||||
properties[self.name] = values \
|
||||
if self.const is None else self.const
|
||||
setattr(namespace, self.dest, properties)
|
||||
|
||||
|
||||
class VmNameAction(QubesAction):
|
||||
|
Loading…
Reference in New Issue
Block a user