@@ -197,6 +197,8 @@ def __init__(self, *args, **kargs):
197197 def __call__ (self , value ):
198198 self .__dict__
199199 return self ._pset .clone (** value )
200+ def _isEmpty (self ) -> bool :
201+ return self ._pset .hasNoParameters ()
200202 def _isValid (self , value ) -> bool :
201203 return isinstance (value ,dict ) or isinstance (value , PSet )
202204 def dumpPython (self , options :PrintOptions = PrintOptions ()) -> str :
@@ -1459,7 +1461,7 @@ def template(self):
14591461 def copy (self ):
14601462 return copy .copy (self )
14611463 def _additionalInitArguments (self , options ):
1462- if self ._template :
1464+ if self ._template and not self . _template . _isEmpty () :
14631465 #NOTE: PSetTemplate.dumpPython does not include the 'cms.' part
14641466 return 'template = cms.' + self ._template .dumpPython (options )
14651467 return None
@@ -2420,6 +2422,10 @@ def testVPSetWithTemplate(self):
24202422 ptest = VPSet (PSet (b = int32 (3 )), template = PSetTemplate (a = required .int32 ))
24212423 self .assertEqual (len (ptest ), 1 )
24222424 self .assertEqual (ptest [0 ].b .value (), 3 )
2425+ self .assertEqual (ptest .dumpPython (),"cms.VPSet(cms.PSet(\n b = cms.int32(3)\n ), \n template = cms.PSetTemplate(\n a = cms.required.int32\n ))"
2426+ )
2427+ ptest = VPSet (template = PSetTemplate ())
2428+ self .assertEqual (ptest .dumpPython (),"cms.VPSet()" )
24232429 #will inject `a=required.int32` into the PSet when starting from a dict()
24242430 ptest = VPSet (dict (), template = PSetTemplate (a = required .int32 ))
24252431 self .assertEqual (len (ptest ), 1 )
0 commit comments