Skip to content

Commit

Permalink
tools: fix PropertyAction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marmarek committed Apr 28, 2017
1 parent 377a821 commit 984ea09
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions qubesmgmt/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def __call__(self, parser, namespace, values, option_string=None):
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):
Expand Down Expand Up @@ -102,8 +107,13 @@ def __init__(self,


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

0 comments on commit 984ea09

Please sign in to comment.