Skip to content

Commit

Permalink
Merge pull request #33673 from makortel/clonePSet
Browse files Browse the repository at this point in the history
Allow edmodule.clone(pset) for PSet to override parameters
  • Loading branch information
cmsbuild committed May 11, 2021
2 parents ee25845 + 880d5d4 commit 6247472
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions FWCore/ParameterSet/python/Mixins.py
Expand Up @@ -414,7 +414,18 @@ def clone(self, *args, **params):
"""
returnValue =_TypedParameterizable.__new__(type(self))
myparams = self.parameters_()


# Prefer parameters given in PSet blocks over those in clone-from module
for block in args:
# Allow __PSet for testing
if type(block).__name__ not in ["PSet", "__PSet"]:
raise ValueError("Only PSets can be passed as unnamed argument blocks. This is a "+type(block).__name__)
for name in block.parameterNames_():
try:
del myparams[name]
except KeyError:
pass

_modifyParametersFromDict(myparams, params, self._Parameterizable__raiseBadSetAttr)
if self._Parameterizable__validator is not None:
myparams["allowAnyLabel_"] = self._Parameterizable__validator
Expand Down Expand Up @@ -868,9 +879,19 @@ def dumpPython(self,options=PrintOptions()):
d = a.clone(__PSet(k=__TestType(42)))
self.assertEqual(d.t.value(), 1)
self.assertEqual(d.k.value(), 42)
# TODO: following case that currently raises an exception
# will be made to work in the near future
self.assertRaises(ValueError, a.clone, __PSet(t=__TestType(42)))
d2 = a.clone(__PSet(t=__TestType(42)))
self.assertEqual(d2.t.value(), 42)
d3 = a.clone(__PSet(t=__TestType(42)),
__PSet(u=__TestType(56)))
self.assertEqual(d3.t.value(), 42)
self.assertEqual(d3.u.value(), 56)
self.assertRaises(ValueError,a.clone,
__PSet(t=__TestType(42)),
__PSet(t=__TestType(56)))
d4 = a.clone(__PSet(t=__TestType(43)), u = 57)
self.assertEqual(d4.t.value(), 43)
self.assertEqual(d4.u.value(), 57)
self.assertRaises(TypeError,a.clone,t=__TestType(43),**{"doesNotExist":57})

e = __Test("MyType")
self.assertEqual(len(e.parameterNames_()), 0)
Expand Down

0 comments on commit 6247472

Please sign in to comment.