From c02fa8e69f3da7cd49c9e0be01122d93cbe47afa Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Mon, 6 May 2024 12:34:20 +0200
Subject: [PATCH] PyUtils: fix flake8-bugbear warnings

Fix warnings about property access with known name.
---
 Tools/PyUtils/python/RootUtils.py                    |  9 ++++-----
 Tools/PyUtils/python/scripts/cmake_newanalysisalg.py | 10 +++++-----
 Tools/PyUtils/python/xmldict.py                      |  4 ++--
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/Tools/PyUtils/python/RootUtils.py b/Tools/PyUtils/python/RootUtils.py
index 2f60ec0086ae..b6c090d940c8 100644
--- a/Tools/PyUtils/python/RootUtils.py
+++ b/Tools/PyUtils/python/RootUtils.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 
 # @file PyUtils.RootUtils
 # @author Sebastien Binet
@@ -129,11 +129,10 @@ def _pythonize_tfile():
             ),
         ]):
         cppyy.load_library("libRootUtilsPyROOTDict")
-        rootutils = getattr(root, "RootUtils")
-        pybytes        = getattr(rootutils, "PyBytes")  # noqa: F841
+        _ = root.RootUtils.PyBytes
         #MN: lines below fail in ROOT6 if PCM from RootUtils is not found
-        read_root_file = getattr(rootutils, "_pythonize_read_root_file")
-        tell_root_file = getattr(rootutils, "_pythonize_tell_root_file")
+        read_root_file = root.RootUtils._pythonize_read_root_file
+        tell_root_file = root.RootUtils._pythonize_tell_root_file
         pass
     def read(self, size=-1):
         """read([size]) -> read at most size bytes, returned as a string.
diff --git a/Tools/PyUtils/python/scripts/cmake_newanalysisalg.py b/Tools/PyUtils/python/scripts/cmake_newanalysisalg.py
index 93ef98b867e8..5f15c1618612 100644
--- a/Tools/PyUtils/python/scripts/cmake_newanalysisalg.py
+++ b/Tools/PyUtils/python/scripts/cmake_newanalysisalg.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 
 # @file PyUtils.scripts.cmt_newanalysisalg
 # @purpose streamline and ease the creation of new athena algs
@@ -329,8 +329,8 @@ def main(args):
 
     
     #following code borrowed from gen_klass
-    hdr = getattr(Templates, 'alg_hdr_template')
-    cxx = getattr(Templates, 'alg_cxx_template')
+    hdr = Templates.alg_hdr_template
+    cxx = Templates.alg_cxx_template
     
     namespace_klass = full_alg_name.replace('::','__')
     namespace_begin,namespace_end = "",""
@@ -417,7 +417,7 @@ DECLARE_COMPONENT( %(klass)s )
       ::: create jobo [%(full_jobo_name)s] and script [%(full_script_name)s] for alg [%(full_alg_name)s]""" %locals()))
    
       #following code borrowed from gen_klass
-      jobo = getattr(Templates, 'jobo_template')
+      jobo = Templates.jobo_template
    
       e = dict( klass=full_alg_name,
                inFile=os.environ['ASG_TEST_FILE_MC'],
@@ -432,7 +432,7 @@ DECLARE_COMPONENT( %(klass)s )
          o_hdr.flush()
          o_hdr.close()
 
-    scripto = getattr(Templates, 'script_template')
+    scripto = Templates.script_template
 
     e = dict( klass=full_alg_name,
               inFile=os.environ['ASG_TEST_FILE_MC'],
diff --git a/Tools/PyUtils/python/xmldict.py b/Tools/PyUtils/python/xmldict.py
index 9d2a6a014481..fe77ad0230ee 100644
--- a/Tools/PyUtils/python/xmldict.py
+++ b/Tools/PyUtils/python/xmldict.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 
 # @file PyUtils/python/xmldict.py
 # @purpose converts an XML file into a python dict, back and forth
@@ -27,7 +27,7 @@ def import_etree():
     m = imp.find_module('etree', [xml_site_package])
 
     etree = imp.load_module('xml.etree', *m)
-    setattr(xml, 'etree', etree)
+    xml.etree = etree
     return etree
 
 etree = import_etree()
-- 
GitLab