-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
VarParsing: prevent TypeError for default of int/float/bool list #45640
Conversation
cms-bot internal usage |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-45640/41153 |
A new Pull Request was created by @IzaakWN for master. It involves the following packages:
@Dr15Jones, @cmsbuild, @makortel, @smuzaffar can you please review it and eventually sign? Thanks. cms-bot commands are listed here |
Thanks @IzaakWN! Would you be able to add your test snippet as a unit test? E.g. something along
should do the job. You can run the test locally with |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-45640/41207 |
Pull request #45640 was updated. @Dr15Jones, @cmsbuild, @makortel, @smuzaffar can you please check and sign again. |
@cmsbuild, please test |
-1 Failed Tests: UnitTests Unit TestsI found 1 errors in the following unit tests: ---> test testCondToolsSiStripBuildersReaders had ERRORS Comparison SummarySummary:
|
Looks like the failed jobs comes from the case where the default list for ints is an empty list: cmssw/CondTools/SiStrip/test/SiStripBadChannelPatcher_cfg.py Lines 20 to 42 in e0cb38f
which passes the new first term in the condition, but not the old second one... cmssw/FWCore/ParameterSet/python/VarParsing.py Lines 416 to 418 in 5089cc1
I can change the condition to ignore empty lists? Something like if (mytype in [VarParsing.varType.bool, VarParsing.varType.int, VarParsing.varType.float] and \
default not in ["", []]) or len (default): # check type to prevent TypeError for bool/int/float defaults
self._lists[name].append (default) # known bug: default can be list |
….parseArguments to unit test
@makortel, to be honest I prefer not to make any changes that will break an unkown large number of scripts, and unit tests that I don't want to be responsible for breaking or fixing. Like you point out, many users implemented workarounds that rely on this behavior, even if it's inconsistent between default and command line (use case (1) in #44630). I propose to merge this PR with the current fix that only prevents a cmssw/FWCore/ParameterSet/python/VarParsing.py Lines 416 to 418 in db50eed
Or, if you prefer, the more general solution with if (mytype in [VarParsing.varType.bool, VarParsing.varType.int, VarParsing.varType.float] and \
not hasattr(default,'__len__')) or len (default): # check type to prevent TypeError for bool/int/float defaults
self._lists[name].append (default) # known bug: default can be list |
Fair enough. Then the cases that do not work with the "list of lists" I listed in #45640 (comment) should, in principle, be fixed, but I'll open separate issues for them.
At this stage let's proceed with minimal effort and continue with this PR as it is. I'll launch last round of tests. |
@cmsbuild, please test |
Playing around it seems I was wrong, this case appears to work (at least with some definition of "work"). |
+1 Size: This PR adds an extra 12KB to repository Comparison SummarySummary:
|
This PR looks ok then. I'll leave signing it to early next week though in order to be around in case something would go bad in IBs (even if the tests here should have included all packages that depend on |
+core |
This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @sextonkennedy, @antoniovilela, @mandrenguyen, @rappoccio (and backports should be raised in the release meeting by the corresponding L2) |
+1 |
PR description:
This PR patches the handling of defaults in
FWCore.ParameterSet.VarParsing
to prevent aTypeError
for the case of an int/float/bool type in combination withVarParsing.multiplicity.list
, where the default is a single int/float/bool value. This bug was described in #44630:Note:
TypeError
with an if statement:https://github.com/IzaakWN/cmssw/blob/dbd4367723a9bcc29fcf308f2902896c2aabbc6e/FWCore/ParameterSet/python/VarParsing.py#L413-L418
[0,1]
→[[0,1]]
.Tagging: @makortel
PR validation:
I setup CMSSW as follows:
To test the behavior, I used this reproducible snippet in the
python3
command line:Before the changes, there are
TypeErrors
:After the changes, the
TypeErrors
are gone, and the single defaults are stored as a list of int/float/bool:PR tests
Following https://cms-sw.github.io/PRWorkflow.html, I did:
As
VarParsing
is used by many python configuration scripts,git cms-checkdeps -a -A
will add 17 additional packages. Not all test are successful, but I checked the same tests fail in a CMSSW project without any changes. As far as I can tell the failures do not come from my side. I assume no workflow contains an exception for theTypeError
above.