Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a.clone(b=dict(c=None)) #22413

Merged
merged 2 commits into from Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions FWCore/ParameterSet/python/Config.py
Expand Up @@ -2962,9 +2962,10 @@ def _mod_fred(obj):
#test removal of parameter
m1 = Modifier()
p = Process("test",m1)
p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
m1.toModify(p.a, fred = None)
p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
m1.toModify(p.a, fred = None, fintstones = dict(fred = None))
self.assertEqual(hasattr(p.a, "fred"), False)
self.assertEqual(hasattr(p.a.fintstones, "fred"), False)
self.assertEqual(p.a.wilma.value(),1)
#test adding a parameter
m1 = Modifier()
Expand Down
10 changes: 10 additions & 0 deletions FWCore/ParameterSet/python/Mixins.py
Expand Up @@ -636,11 +636,18 @@ def _modifyParametersFromDict(params, newParams, errorRaiser, keyDepth=""):
if isinstance(params[key],_Parameterizable):
pset = params[key]
p =pset.parameters_()
oldkeys = set(p.keys())
_modifyParametersFromDict(p,
value,errorRaiser,
("%s.%s" if type(key)==str else "%s[%s]")%(keyDepth,key))
for k,v in p.iteritems():
setattr(pset,k,v)
try:
oldkeys.remove(k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you switch to oldkeys.discard(k) you do not have to use the try...except

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, much cleaner with that.

except KeyError:
pass
for k in oldkeys:
delattr(pset,k)
elif isinstance(params[key],_ValidatingParameterListBase):
if any(type(k) != int for k in value.keys()):
raise TypeError("Attempted to change a list using a dict whose keys are not integers")
Expand Down Expand Up @@ -750,6 +757,7 @@ def __init__(self,*arg,**args):
x = dict(a = 7,
c = dict(gamma = 8),
d = __TestType(9)))
c = a.clone(x = dict(a=None, c=None))
self.assertEqual(a.t.value(),1)
self.assertEqual(a.u.value(),2)
self.assertEqual(b.t.value(),3)
Expand All @@ -760,6 +768,8 @@ def __init__(self,*arg,**args):
self.assertEqual(b.x.c.gamma.value(),8)
self.assertEqual(b.x.d.value(),9)
self.assertEqual(hasattr(b,"w"), False)
self.assertEqual(hasattr(c.x,"a"), False)
self.assertEqual(hasattr(c.x,"c"), False)
self.assertRaises(TypeError,a.clone,None,**{"v":1})
def testModified(self):
class __TestType(_SimpleParameterTypeBase):
Expand Down