From 1d5a1a9b81afcef3cc20d979c6a815cd70e45e6a Mon Sep 17 00:00:00 2001 From: Aksh Gupta Date: Tue, 16 Feb 2021 23:59:01 +0000 Subject: [PATCH] chore: refactor code quality issues --- setup.cfg | 2 ++ src/pyhf/modifiers/__init__.py | 9 ++++----- src/pyhf/pdf.py | 8 ++++---- src/pyhf/readxml.py | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7fbfe11513..3a1ac61569 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,8 +21,10 @@ classifiers = Topic :: Scientific/Engineering Topic :: Scientific/Engineering :: Physics Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 + Programming Language :: Python :: Implementation :: CPython [options] setup_requires = diff --git a/src/pyhf/modifiers/__init__.py b/src/pyhf/modifiers/__init__.py index b39e7164db..1b307ce2e9 100644 --- a/src/pyhf/modifiers/__init__.py +++ b/src/pyhf/modifiers/__init__.py @@ -146,7 +146,7 @@ def wrapper(cls): if not args: # called like @modifier(name='foo', constrained=False, pdf_type='normal', op_code='addition') return _modifier(name, constrained, pdf_type, op_code) - elif len(args) == 1: + if len(args) == 1: # called like @modifier if not callable(args[0]): raise ValueError('You must decorate a callable python object') @@ -158,10 +158,9 @@ def wrapper(cls): op_code=op_code, ) return args[0] - else: - raise ValueError( - f'@modifier must be called with only keyword arguments, @modifier(name=\'foo\'), or no arguments, @modifier; ({len(args):d} given)' - ) + raise ValueError( + f'@modifier must be called with only keyword arguments, @modifier(name=\'foo\'), or no arguments, @modifier; ({len(args):d} given)' + ) from .histosys import histosys, histosys_combined diff --git a/src/pyhf/pdf.py b/src/pyhf/pdf.py index ef94950886..ee2b679354 100644 --- a/src/pyhf/pdf.py +++ b/src/pyhf/pdf.py @@ -151,7 +151,7 @@ def _nominal_and_modifiers_from_spec(config, spec): if mtype == 'histosys': lo_data = thismod['data']['lo_data'] if thismod else nom hi_data = thismod['data']['hi_data'] if thismod else nom - maskval = True if thismod else False + maskval = bool(thismod) mega_mods[key][s]['data']['lo_data'] += lo_data mega_mods[key][s]['data']['hi_data'] += hi_data mega_mods[key][s]['data']['nom_data'] += nom @@ -159,7 +159,7 @@ def _nominal_and_modifiers_from_spec(config, spec): nom ) # broadcasting elif mtype == 'normsys': - maskval = True if thismod else False + maskval = bool(thismod) lo_factor = thismod['data']['lo'] if thismod else 1.0 hi_factor = thismod['data']['hi'] if thismod else 1.0 mega_mods[key][s]['data']['nom_data'] += [1.0] * len(nom) @@ -171,7 +171,7 @@ def _nominal_and_modifiers_from_spec(config, spec): nom ) # broadcasting elif mtype in ['normfactor', 'shapefactor', 'lumi']: - maskval = True if thismod else False + maskval = bool(thismod) mega_mods[key][s]['data']['mask'] += [maskval] * len( nom ) # broadcasting @@ -180,7 +180,7 @@ def _nominal_and_modifiers_from_spec(config, spec): if mtype == 'shapesys': maskval = [(x > 0 and y > 0) for x, y in zip(uncrt, nom)] else: - maskval = [True if thismod else False] * len(nom) + maskval = [bool(thismod)] * len(nom) mega_mods[key][s]['data']['mask'] += maskval mega_mods[key][s]['data']['uncrt'] += uncrt mega_mods[key][s]['data']['nom_data'] += nom diff --git a/src/pyhf/readxml.py b/src/pyhf/readxml.py index fdd90daea8..8c1b3e857a 100644 --- a/src/pyhf/readxml.py +++ b/src/pyhf/readxml.py @@ -304,7 +304,7 @@ def dedupe_parameters(parameters): duplicates = {} for p in parameters: duplicates.setdefault(p['name'], []).append(p) - for parname in duplicates.keys(): + for parname in duplicates: parameter_list = duplicates[parname] if len(parameter_list) == 1: continue