diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c525a92d4313976c7212b7e2540e188fb157505f..17c766e84eaa5b742db41c89e807019ff09e3d3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,11 @@ repos: "--skip", "Phys/AnalysisPython/*,Phys/DaVinciTrackScaling/*" ] + - repo: https://github.com/asottile/pyupgrade + rev: v3.4.0 + hooks: + - id: pyupgrade + args: ["--py39-plus"] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: diff --git a/Phys/AnalysisPython/python/AnalysisPython/DebugMCAssoc.py b/Phys/AnalysisPython/python/AnalysisPython/DebugMCAssoc.py index e77c0e0dc5cce9f134fe731204b0d1d5212cdac3..95d8b0a0046c9d589f17fed1382e985295f93b38 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/DebugMCAssoc.py +++ b/Phys/AnalysisPython/python/AnalysisPython/DebugMCAssoc.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -9,7 +8,6 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from __future__ import print_function from AnalysisPython import Helpers diff --git a/Phys/AnalysisPython/python/AnalysisPython/Dir.py b/Phys/AnalysisPython/python/AnalysisPython/Dir.py index 5f82cbecb0d81d053f16a8bf21da56f00e4bc705..9ec52d78829cea84699064287d3c72981f7eca50 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/Dir.py +++ b/Phys/AnalysisPython/python/AnalysisPython/Dir.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -9,7 +8,6 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from __future__ import print_function from GaudiPython.Bindings import iDataSvc, SUCCESS, FAILURE diff --git a/Phys/AnalysisPython/python/AnalysisPython/DumpRootObjects.py b/Phys/AnalysisPython/python/AnalysisPython/DumpRootObjects.py index d1de739001ee4f730f1ce0d7c7f4885fc4c401eb..402447d141af20554004ac29965cbaeba36d05da 100755 --- a/Phys/AnalysisPython/python/AnalysisPython/DumpRootObjects.py +++ b/Phys/AnalysisPython/python/AnalysisPython/DumpRootObjects.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -44,7 +43,6 @@ And it is based on the LoKi project: ``C++ ToolKit for Smart and Friendly Physics Analysis'' """ # ============================================================================= -from __future__ import print_function __author__ = "Vanya BELYAEV Ivan.Belyaev@itep.ru" __date__ = "2012-03-16" diff --git a/Phys/AnalysisPython/python/AnalysisPython/Functors.py b/Phys/AnalysisPython/python/AnalysisPython/Functors.py index 6ca73b907fe3260c2586f38f6248aa35b48d026f..ad33642445522ec9324bc4bc49e98a4f93f1e808 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/Functors.py +++ b/Phys/AnalysisPython/python/AnalysisPython/Functors.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -28,7 +27,6 @@ analysis in GaudiPython. it exports the following classes: - ContainerLoop - ContainerRecursiveLoop """ -from __future__ import print_function __author__ = "Juan PALACIOS juan.palacios@nikhef.nl" # ============================================================================== diff --git a/Phys/AnalysisPython/python/AnalysisPython/Helpers.py b/Phys/AnalysisPython/python/AnalysisPython/Helpers.py index 2fd79ba2154245f4d6e6c4cdddd58353d661ec59..1970c88d85b27b3a4726290d9257da2b52d6d4b4 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/Helpers.py +++ b/Phys/AnalysisPython/python/AnalysisPython/Helpers.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -14,7 +13,6 @@ This module contains a set of random helper functions for GaudiPython analysis. """ -from __future__ import print_function __author__ = "Juan PALACIOS juan.palacios@nikhef.nl" from ROOT import Double diff --git a/Phys/AnalysisPython/python/AnalysisPython/HistoUtils.py b/Phys/AnalysisPython/python/AnalysisPython/HistoUtils.py index 26a4c57d1550c1a7d6e677da312da332baa766c9..bfe115ce9f5b8d553d467ef8eb754bbb3ed441d1 100755 --- a/Phys/AnalysisPython/python/AnalysisPython/HistoUtils.py +++ b/Phys/AnalysisPython/python/AnalysisPython/HistoUtils.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # diff --git a/Phys/AnalysisPython/python/AnalysisPython/Logger.py b/Phys/AnalysisPython/python/AnalysisPython/Logger.py index 7a4146a1658307310c57ca93fae5a0e52605f7e3..3e4f3d077e89176ec7c4bb3077dd5ec7199a8e1a 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/Logger.py +++ b/Phys/AnalysisPython/python/AnalysisPython/Logger.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -267,7 +266,7 @@ def getLogger( # @endcode # @author Vanya BELYAEV Ivan.Belyaev@itep.ru # @date 2014-01-1 -class LogLevel(object): +class LogLevel: """Temporarily enable/disable certain logger levels >>> with LogLevel( logging.CRITICAL ) : ... do something here ... @@ -490,7 +489,7 @@ def make_colors(): # with ColorLogging(): # ... do something ... # @endcode -class ColorLogging(object): +class ColorLogging: """Simple context manager to swith on coloring >>> with ColorLogging() : @@ -567,7 +566,7 @@ def noColor(): # with KeepColorLogging(): # ... do something ... # @endcode -class KeepColorLogging(object): +class KeepColorLogging: """Simple context manager to preserve coloring >>> with KeepColorLogging() : diff --git a/Phys/AnalysisPython/python/AnalysisPython/Rewind.py b/Phys/AnalysisPython/python/AnalysisPython/Rewind.py index f9dde9f8795da896f1a15b6987d35d64cede5406..ca8b419cb55e83d1089d1407f68b750bb70040b4 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/Rewind.py +++ b/Phys/AnalysisPython/python/AnalysisPython/Rewind.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -9,7 +8,6 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -from __future__ import print_function from GaudiPython.Bindings import iHistogramSvc, AppMgr, SUCCESS, FAILURE from AnalysisPython import Dir diff --git a/Phys/AnalysisPython/python/AnalysisPython/__init__.py b/Phys/AnalysisPython/python/AnalysisPython/__init__.py index 219e65d958c9f99da438cb0cbacd1b61aa7dc386..fec9a66c4d5bd748c2901f3bcb42262388cb7791 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/__init__.py +++ b/Phys/AnalysisPython/python/AnalysisPython/__init__.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # diff --git a/Phys/AnalysisPython/python/AnalysisPython/uStat.py b/Phys/AnalysisPython/python/AnalysisPython/uStat.py index 664ef00b4b9946447a98344aed4333639f570c4b..19659dcc0d7acf202120a18bf0703c203373d38b 100644 --- a/Phys/AnalysisPython/python/AnalysisPython/uStat.py +++ b/Phys/AnalysisPython/python/AnalysisPython/uStat.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -61,7 +60,6 @@ Usage is fairly trivial: """ # ============================================================================ -from __future__ import print_function __author__ = "Vanya BELYAEV Ivan.Belyaev@cern.ch" __date__ = "2010-09-21" diff --git a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/covariance_scale.py b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/covariance_scale.py index 39d4cf3430ef583c2369e26744894f3def5a0b96..d11fbd40d5212d2ca46aa1b0e8ecc8b1dc5b4d9a 100644 --- a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/covariance_scale.py +++ b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/covariance_scale.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -34,7 +34,6 @@ """ # ============================================================================ -from __future__ import print_function __author__ = "Vanya BELYAEV Ivan.Belyaev@itep.ru" __date__ = "2013-04-20" @@ -87,7 +86,7 @@ smear = PARAM( histo.toString(), name="Scale", type="Histo1D", - comment="Covariance scale %s %s %s " % (sim, reco, year), + comment=f"Covariance scale {sim} {reco} {year} ", ) document = DDDB( diff --git a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_scale.py b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_scale.py index 81a9550016e039d7f860260c43ee8334d2a1f23e..f06bbaa3efdd084d71e3c20592e249a76e5a958a 100644 --- a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_scale.py +++ b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_scale.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -47,7 +47,6 @@ Input data are specified close to the start of the script """ # ============================================================================ -from __future__ import print_function __author__ = "Vanya BELYAEV Ivan.Belyaev@itep.ru" __date__ = "2013-04-20" @@ -132,28 +131,28 @@ def buildXML(reco, year, idp_plus, idp_minus, offsets, delta): str(delta), name="Delta", type="double", - comment="Global delta scale %s %s" % (reco, year), + comment=f"Global delta scale {reco} {year}", ) xml_idplus = PARAM( idp_plus.toString(), name="IdpPlus", type="Histo2D", - comment="Calibration for IdpPlus %s %s" % (reco, year), + comment=f"Calibration for IdpPlus {reco} {year}", ) xml_idpminus = PARAM( idp_minus.toString(), name="IdpMinus", type="Histo2D", - comment="Calibration for IdpMinus %s %s" % (reco, year), + comment=f"Calibration for IdpMinus {reco} {year}", ) xml_offsets = PARAM( offsets_to_histo(offsets, "Run-dependent offsets").toString(), name="Offsets", type="Histo1D", - comment="Run-dependent offsets %s %s" % (reco, year), + comment=f"Run-dependent offsets {reco} {year}", ) document = DDDB( diff --git a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_smear.py b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_smear.py index ed235539a4622577c16b676ab61912358b2c57a2..b99ee41771f91ad5ea6611e1f96893b00165f36a 100644 --- a/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_smear.py +++ b/Phys/DaVinciTrackScaling/python/DaVinciTrackScaling/momentum_smear.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -34,7 +34,6 @@ """ # ============================================================================ -from __future__ import print_function __author__ = "Vanya BELYAEV Ivan.Belyaev@itep.ru" __date__ = "2013-04-20" @@ -94,7 +93,7 @@ smear = PARAM( histo.toString(), name="Smear", type="Histo1D", - comment="Momentum Smearing %s %s %s " % (sim, reco, year), + comment=f"Momentum Smearing {sim} {reco} {year} ", ) document = DDDB( diff --git a/Phys/FunTuple/python/FunTuple/FunctorCollection.py b/Phys/FunTuple/python/FunTuple/FunctorCollection.py index 78d65c13333dfc94db60ae4f013992697335ba5f..04e05d8837e8acfb6eedeb265737c6efefeb28c7 100644 --- a/Phys/FunTuple/python/FunTuple/FunctorCollection.py +++ b/Phys/FunTuple/python/FunTuple/FunctorCollection.py @@ -146,10 +146,7 @@ class FunctorCollection: return ( f"<FunctorCollection object at {hex(id(self))}:\n" + "".join( - [ - " {0}: {1}\n".format(key, val) - for key, val in (self.functor_dict).items() - ] + [f" {key}: {val}\n" for key, val in (self.functor_dict).items()] ) + ">" ) diff --git a/Phys/FunTuple/python/FunTuple/functorcollections.py b/Phys/FunTuple/python/FunTuple/functorcollections.py index c216c08235e5a743ca23aff5f4ab9741532c2739..810d804e69864672c44daec83b0c72a0c9a8f5e7 100644 --- a/Phys/FunTuple/python/FunTuple/functorcollections.py +++ b/Phys/FunTuple/python/FunTuple/functorcollections.py @@ -15,7 +15,7 @@ Refer to the docstrings of the collections in this submodule for examples of typical usage. """ -from typing import List, Optional +from typing import Optional from GaudiKernel import SystemOfUnits # type: ignore[import] from GaudiConf.LbExec import HltSourceID # type: ignore[import] @@ -25,7 +25,7 @@ from PyConf.application import make_data_with_FetchDataFromFile # type: ignore[ from PyConf.dataflow import DataHandle # type: ignore[import] from PyConf.components import Algorithm # type: ignore[import] from PyConf.Algorithms import HltTisTosAlg, Hlt1TrueSimEffAlg, Hlt2TrueSimEffAlg # type: ignore[import] -import DaVinciMCTools # for MCReconstructible, MCReconstructed and MCTruthAndBkgCat helper classes +import DaVinciMCTools # type: ignore[import] from DecayTreeFitter import DecayTreeFitter # type: ignore[import] from .FunctorCollection import FunctorCollection @@ -83,7 +83,7 @@ def EventInfo() -> FunctorCollection: def SelectionInfo( - *, selection_type: HltSourceID, trigger_lines: List[str] + *, selection_type: HltSourceID, trigger_lines: list[str] ) -> FunctorCollection: """ " Event-level collection of most-used functors for tupling trigger/Sprucing information. @@ -126,14 +126,14 @@ def SelectionInfo( def _HltMCTrueSimEff( *, selection_type: HltSourceID, - trigger_lines: List[str], + trigger_lines: list[str], mcp_data: DataHandle, dec_reports: DataHandle, mc2IDLink: DataHandle, sel_reports: DataHandle = make_data_with_FetchDataFromFile( "dummy_sel_rep_location" ), - cand_locations: List[str] = ["dummy_line_name_Decision_loc"], + cand_locations: list[str] = ["dummy_line_name_Decision_loc"], ): """ Candidate-level collection to store TrueSim efficiencies for HltEfficiencyChecker @@ -197,7 +197,7 @@ def _HltMCTrueSimEff( def HltTisTos( - *, selection_type: HltSourceID, trigger_lines: List[str], data: DataHandle + *, selection_type: HltSourceID, trigger_lines: list[str], data: DataHandle ) -> FunctorCollection: """ Candidate-level collection to store TIS (Trigger Independent of Signal) or TOS (Trigger On Signal)