From 1dfa4a0d4e26e8ffa204b98464d6befdbb8a7728 Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Wed, 5 Sep 2018 11:35:23 +0200
Subject: [PATCH] AthenaCommon: python code style cleanup

Add a flake8 unit test and make the python code compliant.


Former-commit-id: 51bdb0ef448caee659c72e83aa2122ab618b7b0b
---
 Control/AthenaCommon/CMakeLists.txt           |  4 ++
 Control/AthenaCommon/python/AlgScheduler.py   |  6 +--
 Control/AthenaCommon/python/AlgSequence.py    |  8 ++--
 Control/AthenaCommon/python/AppMgr.py         | 46 +++++++++----------
 Control/AthenaCommon/python/AthApi.py         | 16 ++-----
 .../AthenaCommon/python/AthOptionsParser.py   | 20 ++++----
 .../AthenaCommon/python/AtlasThreadedJob.py   | 13 ++----
 .../python/AtlasUnixGeneratorJob.py           |  4 +-
 .../python/AtlasUnixStandardJob.py            |  5 +-
 Control/AthenaCommon/python/CFElements.py     |  2 +-
 Control/AthenaCommon/python/CfgMergerLib.py   |  1 -
 Control/AthenaCommon/python/ChapPy.py         | 26 +++++------
 .../AthenaCommon/python/ConcurrencyFlags.py   |  6 +--
 Control/AthenaCommon/python/Configurable.py   | 23 +++++-----
 Control/AthenaCommon/python/ConfigurableDb.py | 16 +++----
 .../AthenaCommon/python/ConfigurableMeta.py   |  4 +-
 .../python/ConfigurationCleanup.py            |  7 +--
 .../AthenaCommon/python/ConfiguredFactory.py  | 10 ++--
 Control/AthenaCommon/python/DumpProperties.py | 19 ++++----
 Control/AthenaCommon/python/GlobalFlags.py    | 12 ++---
 Control/AthenaCommon/python/Include.py        |  8 ++--
 Control/AthenaCommon/python/JobProperties.py  | 22 +++++----
 Control/AthenaCommon/python/KeyStore.py       | 38 ++++++++-------
 Control/AthenaCommon/python/ObjectBrowser.py  | 12 ++---
 .../AthenaCommon/python/PhysicalConstants.py  |  4 +-
 .../python/PoolInputFileListBase.py           | 13 +++---
 .../AthenaCommon/python/PropertiesManip.py    |  4 +-
 Control/AthenaCommon/python/PropertyProxy.py  | 17 +++----
 Control/AthenaCommon/python/ResourceLimits.py |  6 +--
 .../AthenaCommon/python/ServicesPythonize.py  |  4 +-
 Control/AthenaCommon/python/ShellEscapes.py   | 10 ++--
 31 files changed, 183 insertions(+), 203 deletions(-)

diff --git a/Control/AthenaCommon/CMakeLists.txt b/Control/AthenaCommon/CMakeLists.txt
index 023a4bf985c..de809b8cd17 100644
--- a/Control/AthenaCommon/CMakeLists.txt
+++ b/Control/AthenaCommon/CMakeLists.txt
@@ -32,3 +32,7 @@ atlas_add_test( KeyStoreUnitTests SCRIPT test/test_KeyStoreUnitTests.sh
 atlas_add_test( CFElementsTest SCRIPT python -m unittest -v AthenaCommon.CFElements
 		POST_EXEC_SCRIPT nopost.sh ) 
 
+# Check python syntax:
+atlas_add_test( flake8
+   SCRIPT flake8 --select=F,E101,E112,E113,E7,E9,W6 --ignore=E701 ${CMAKE_CURRENT_SOURCE_DIR}/python
+   POST_EXEC_SCRIPT nopost.sh )
diff --git a/Control/AthenaCommon/python/AlgScheduler.py b/Control/AthenaCommon/python/AlgScheduler.py
index 440df7d574f..e768b43b965 100644
--- a/Control/AthenaCommon/python/AlgScheduler.py
+++ b/Control/AthenaCommon/python/AlgScheduler.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # Configuration for the Hive Algorithm Scheduler.
 #
@@ -34,14 +34,14 @@ class AlgScheduler:
         """Setup Algorithm Scheduler"""
 
         from AppMgr import ServiceMgr as svcMgr
-        from Constants import VERBOSE, DEBUG, INFO, ERROR
+        from Constants import INFO
 
         from ConcurrencyFlags import jobproperties as jps
         from AthenaCommon.Logging import logging
 
         self.log = logging.getLogger( 'AlgScheduler' )
 
-        if (theSched == None) :
+        if (theSched is None) :
             from GaudiHive.GaudiHiveConf import AvalancheSchedulerSvc
             svcMgr += AvalancheSchedulerSvc()
             self.SchedulerSvc = svcMgr.AvalancheSchedulerSvc
diff --git a/Control/AthenaCommon/python/AlgSequence.py b/Control/AthenaCommon/python/AlgSequence.py
index 72f036da57c..d99ea4587db 100755
--- a/Control/AthenaCommon/python/AlgSequence.py
+++ b/Control/AthenaCommon/python/AlgSequence.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/AlgSequence.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -32,7 +32,7 @@ class AthSequencer( GaudiSequencerConf.AthSequencer ):
        props = super( AthSequencer, self ).getProperties()
 
        ## correctly display the value of 'Members' by gathering children
-       if props.has_key( 'Members' ):
+       if 'Members' in props:
           props['Members'] = [ c.getFullName() for c in self.getChildren() ]
        return props
 
@@ -74,7 +74,7 @@ if hasattr(GaudiSequencerConf, 'AthRetrySequencer'):
             props = super( AthRetrySequencer, self ).getProperties()
 
             ## correctly display the value of 'Members' by gathering children
-            if props.has_key( 'Members' ):
+            if 'Members' in props:
                 props['Members'] = [ c.getFullName() for c in self.getChildren() ]
             return props
 
@@ -119,7 +119,7 @@ if hasattr(GaudiSequencerConf, 'AthAnalysisSequencer'):
             props = super( AthAnalysisSequencer, self ).getProperties()
 
             ## correctly display the value of 'Members' by gathering children
-            if props.has_key( 'Members' ):
+            if 'Members' in props:
                 props['Members'] = [ c.getFullName() for c in self.getChildren() ]
             return props
 
diff --git a/Control/AthenaCommon/python/AppMgr.py b/Control/AthenaCommon/python/AppMgr.py
index 73977078a52..2969d7ac967 100755
--- a/Control/AthenaCommon/python/AppMgr.py
+++ b/Control/AthenaCommon/python/AppMgr.py
@@ -173,16 +173,16 @@ class AthAppMgr( AppMgr ):
       
    def __init__( self, name = "ApplicationMgr", **kw ):
       kw['name'] = name
-      if not kw.has_key('outputLevel'): kw['outputLevel'] = 3
-      if not kw.has_key('jobOptions') : kw['jobOptions']  = None
+      if 'outputLevel' not in kw: kw['outputLevel'] = 3
+      if 'jobOptions' not in kw : kw['jobOptions']  = None
 
     # some Atlas defaults
-      if not kw.has_key('JobOptionsPath'): kw['JobOptionsPath'] = ""
-      if not kw.has_key('JobOptionsType'): kw['JobOptionsType'] = "NONE"
-      if not kw.has_key('EventLoop'):      kw['EventLoop']="AthenaEventLoopMgr"
-      if not kw.has_key('OutStreamType'):
+      if 'JobOptionsPath' not in kw: kw['JobOptionsPath'] = ""
+      if 'JobOptionsType' not in kw: kw['JobOptionsType'] = "NONE"
+      if 'EventLoop' not in kw:      kw['EventLoop']="AthenaEventLoopMgr"
+      if 'OutStreamType' not in kw:
          kw['OutStreamType'] = "AthenaOutputStream"
-      if not kw.has_key('StatusCodeCheck'): kw['StatusCodeCheck'] = True
+      if 'StatusCodeCheck' not in kw: kw['StatusCodeCheck'] = True
 
     # always the case in ATLAS (need early or ExtSvc should be a no-op, too)
       kw['ExtSvcCreates'] = False
@@ -202,7 +202,7 @@ class AthAppMgr( AppMgr ):
       self.__class__.OutStream = OldToNewSequenceProxy( self.__dict__[ '_streams' ] )
 
     # install services
-      svcMgr = self.serviceMgr()
+      svcMgr = self.serviceMgr()  # noqa: F841
 
     # external option (TODO: receive this cleanly; AthOptionsParser doesn't manage results, and
     # can't be called directly due to transforms etc.)
@@ -260,7 +260,7 @@ class AthAppMgr( AppMgr ):
       def _build():
          Logging.log.debug ("building master sequence...")
          athMasterSeq = _as.AthSequencer ("AthMasterSeq",Sequential = True, StopOverride=True)
-         athFilterSeq = _as.AthSequencer ("AthFilterSeq"); 
+         athFilterSeq = _as.AthSequencer ("AthFilterSeq")
          athBeginSeq  = _as.AthSequencer ("AthBeginSeq",Sequential=True)
          athCondSeq   = _as.AthSequencer ("AthCondSeq")
          athAlgSeq    = _as.AthSequencer ("AthAlgSeq")
@@ -363,14 +363,14 @@ class AthAppMgr( AppMgr ):
 
  # explicit user calls
    def addSequence( self, seq ):
-      if not seq in self._sequences:
+      if seq not in self._sequences:
          self._sequences.append( seq )
 
    def removeSequence( self, seq ):
       self._sequences.remove( seq )
 
    def addOutputStream( self, stream ):
-      if not stream in self._streams.getChildren():
+      if stream not in self._streams.getChildren():
          self._streams += stream
 
    def removeOutputStream( self, stream ):
@@ -378,14 +378,14 @@ class AthAppMgr( AppMgr ):
          
  # override toolSvc to handle the transitional one
    def toolSvc( self, name='ToolSvc' ):
-      if not '_toolsvc' in self.__dict__:
+      if '_toolsvc' not in self.__dict__:
          self.__dict__[ '_toolsvc' ] = GaudiSvcConf.ToolSvc( name )
       return self._toolsvc
    toolsvc = toolSvc
 
  # same for serviceMgr
    def serviceMgr( self ):
-      if not '_servicemgr' in self.__dict__:
+      if '_servicemgr' not in self.__dict__:
          self.__dict__[ '_servicemgr' ] = AthServiceManager( 'ServiceManager' )
       return self._servicemgr
    servicemgr = serviceMgr
@@ -393,7 +393,7 @@ class AthAppMgr( AppMgr ):
    def bootProps(self):
       props = {}
       for k in self.getProperties().keys():
-         if not k in [ "Go", "Exit", "AuditInitialize", "AuditFinalize" ]:
+         if k not in [ "Go", "Exit", "AuditInitialize", "AuditFinalize" ]:
             props[k] = self.getDefaultProperty(k)
             if hasattr(self, k):
                props[k] = getattr(self, k)
@@ -430,9 +430,10 @@ class AthAppMgr( AppMgr ):
          self.__dict__['state'] = getattr(self._cppApp, 'state')
          for k,v in selfOptions.items():
             setattr(self._cppApp,k,v)
-         self.__dict__['CreateSvc'] = _createSvc; del _createSvc
+         self.__dict__['CreateSvc'] = _createSvc
+         del _createSvc
 
-      import GaudiPython # this module might have disappeared b/c of cleansing
+      import GaudiPython # this module might have disappeared b/c of cleansing # noqa: F401
       return self._cppApp
    
    @property
@@ -575,7 +576,7 @@ class AthAppMgr( AppMgr ):
          _createSvc[0] != svcMgr.ToolSvc.getFullName():
          _createSvc = [ svcMgr.ToolSvc.getFullName() ] + _createSvc
 
-      if self.__dict__.has_key('CreateSvc'):
+      if 'CreateSvc' in self.__dict__:
          del self.__dict__['CreateSvc']
       handle.__dict__['CreateSvc'] = [ s for s in _createSvc ]
       
@@ -698,7 +699,7 @@ class AthAppMgr( AppMgr ):
          return sc
 
     # determine number of events
-      if nEvt == None:
+      if nEvt is None:
          nEvt = self.EvtMax            # late, as sequences may have changed it
 
     # another communication that needs improving (TODO) ...
@@ -768,8 +769,7 @@ class AthAppMgr( AppMgr ):
          self._exitstate = ExitCodes.FIN_ALG_FAILURE
       try:
          if not self._cppApp:
-            raise RuntimeError, \
-                  "C++ application not instantiated : Nothing to finalize !"
+            raise RuntimeError("C++ application not instantiated : Nothing to finalize !")
          # Set threaded flag to release the GIL when finalizing in the c++
          from ConcurrencyFlags import jobproperties as jp
          finalizeMethod = self.getHandle()._appmgr.finalize
@@ -819,7 +819,7 @@ class AthAppMgr( AppMgr ):
       if sc.isFailure() and not self._exitstate:
          self._exitstate = ExitCodes.INI_ALG_FAILURE
 
-      if nEvt == None:
+      if nEvt is None:
          nEvt = self.curEvent() + 1
 
       try:
@@ -885,8 +885,8 @@ class AthAppMgr( AppMgr ):
       self.__report_python_profile()
 
       Logging.log.info( 'leaving with code %d: "%s"',
-         self._exitstate, ExitCodes.what( self._exitstate ) )
-      sys.exit( code == None and self._exitstate or code )
+                        self._exitstate, ExitCodes.what( self._exitstate ) )
+      sys.exit( code is None and self._exitstate or code )
 
 
 ### global objects for export ------------------------------------------------
diff --git a/Control/AthenaCommon/python/AthApi.py b/Control/AthenaCommon/python/AthApi.py
index 282c593f214..3620642c812 100644
--- a/Control/AthenaCommon/python/AthApi.py
+++ b/Control/AthenaCommon/python/AthApi.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # @file AthenaCommon/python/AthApi.py
 # @purpose API for driving athena
@@ -18,7 +18,7 @@ __all__ = [
     ]
 
 import sys, os
-if not '' in sys.path:
+if '' not in sys.path:
     sys.path.insert(0, '')
     
 from . import ExitCodes
@@ -196,8 +196,6 @@ class AthApp(object):
         from . import ResourceLimits
         ResourceLimits.SetMaxLimits()
 
-        try: import cPickle as pickle
-        except ImportError: import pickle
         import PyUtils.dbsqlite as dbs
         db = dbs.open(cfg_name, 'r')
 
@@ -463,8 +461,6 @@ class AthApp(object):
 ##         return optionstr  
 
 ## --- helper functions for configuration storage -----------------------------
-try:     import cPickle as pickle
-except ImportError: import pickle
 import PyUtils.dbsqlite as dbs
 from collections import defaultdict
 def store_configuration(cfg_fname=None):
@@ -537,9 +533,7 @@ def store_configuration(cfg_fname=None):
     cfg['jobopts'] = jobo_cfg
 
     pycomps = []
-    import sys
-    from .AppMgr import ServiceMgr as svcMgr
-        
+
     # all other pycomps
     from .Configurable import Configurable as C
     for c in C.allConfigurables.itervalues():
@@ -608,7 +602,7 @@ def enter_interactive_loop(banner=None, app=None, options=None):
         except NameError:
             pass
     # this will import .pythonrc.py as a side effect
-    import user
+    import user  # noqa: 401
 
     # use of shell escapes
     from . import ShellEscapes as SE
@@ -621,7 +615,7 @@ def enter_interactive_loop(banner=None, app=None, options=None):
     shell = AthenaInteractiveConsole(locals=namespace)
     shell.interact(banner=banner)
 
-from PyUtils.Decorators import forking
+#from PyUtils.Decorators import forking
 #@forking
 def _app_configure(cfg, ascii_cfg_name, extra_options=None):
     cfg << """
diff --git a/Control/AthenaCommon/python/AthOptionsParser.py b/Control/AthenaCommon/python/AthOptionsParser.py
index 74a5b23bce8..58ff9b67b7c 100644
--- a/Control/AthenaCommon/python/AthOptionsParser.py
+++ b/Control/AthenaCommon/python/AthOptionsParser.py
@@ -175,7 +175,7 @@ def parse(chk_tcmalloc=True):
     if ldpreload.find(libname) == -1:
         using_tcmalloc = False
         if (os.getenv('USETCMALLOC') == '1' or
-            os.getenv('USETCMALLOC') == None):
+            os.getenv('USETCMALLOC') is None):
             warn_tcmalloc = True
         for arg in sys.argv[1:]:
             if arg == '--tcmalloc':
@@ -192,13 +192,12 @@ def parse(chk_tcmalloc=True):
     
     # emulated GNU getopt for p2.2:
     # collect scripts and options (special case for '-p')
-    _p = 0
     args = sys.argv[1:]
     for arg in args:
         if (arg[-3:] == '.py' and 
             (arg[:7] != '--trace' )):
             scripts.append(arg)
-        elif arg[-4:] == '.pkl' and not '=' in arg:
+        elif arg[-4:] == '.pkl' and '=' not in arg:
             fromdb = arg
             opts.default_jobopt = ''
         elif arg == '-':     # rest are user opts, save and done
@@ -206,7 +205,6 @@ def parse(chk_tcmalloc=True):
             break
         else:
             _opts.append(arg)
-        _p = 0
 
     # process user options
     try:
@@ -246,7 +244,7 @@ def parse(chk_tcmalloc=True):
         elif opt in ("-d", "--debug"):
             if not arg:
                 arg = "init"
-            elif not arg in DbgStage.allowed_values:
+            elif arg not in DbgStage.allowed_values:
                 _help_and_exit()
             opts.dbg_stage = arg
 
@@ -281,11 +279,11 @@ def parse(chk_tcmalloc=True):
             sys.exit()
             
         elif opt in ("--leak-check", "--leak-check-execute", "--delete-check"):
-            if using_tcmalloc == False:
+            if not using_tcmalloc:
                 # early import is needed for proper offloading later
-                import Hephaestus.MemoryTracker as memtrack
+                import Hephaestus.MemoryTracker as memtrack    # noqa: F401
                 if opt == "--delete-check":
-                    import Hephaestus.DeleteChecker
+                    import Hephaestus.DeleteChecker            # noqa: F401
                     opts.memchk_mode = 'delete-check'
                 else:
                     opts.memchk_mode = 'leak-check'
@@ -326,7 +324,7 @@ def parse(chk_tcmalloc=True):
                 for a in pmon_args:
                     if a.startswith(('+','-')):
                         a = a[1:]
-                    if not a in allowed:
+                    if a not in allowed:
                         print "invalid argument to perfmon [%s]" % (a,)
                         print "allowed values are: %r" % (allowed,)
                         _help_and_exit()
@@ -448,12 +446,12 @@ def parse(chk_tcmalloc=True):
         jps.ConcurrencyFlags.NumProcs = envNProcs
     
     # for the benefit of PyROOT
-    if not opts.display and not '-b' in sys.argv:
+    if not opts.display and '-b' not in sys.argv:
         sys.argv = sys.argv[:1] + ['-b'] + sys.argv[1:]
 
     # user decision about TDAQ ERS signal handlers
     if opts.enable_ers_hdlr:
-        if os.environ.has_key('TDAQ_ERS_NO_SIGNAL_HANDLERS'):
+        if 'TDAQ_ERS_NO_SIGNAL_HANDLERS' in os.environ:
             del os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS']
     else:
         os.environ['TDAQ_ERS_NO_SIGNAL_HANDLERS']='1'
diff --git a/Control/AthenaCommon/python/AtlasThreadedJob.py b/Control/AthenaCommon/python/AtlasThreadedJob.py
index 4c29eeec21d..0c5c38820fb 100644
--- a/Control/AthenaCommon/python/AtlasThreadedJob.py
+++ b/Control/AthenaCommon/python/AtlasThreadedJob.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 ## @file AtlasThreadedJob.py
 ## @brief py-module to configure the Athena AppMgr for threaded (Hive) jobs
@@ -8,9 +8,7 @@
 def _setupAtlasThreadedJob():
     from AppMgr import theApp
     from AppMgr import ServiceMgr as svcMgr
-
-    import SystemOfUnits as Units
-    from Constants import VERBOSE, DEBUG, INFO, ERROR
+    import Constants
 
     from ConcurrencyFlags import jobproperties as jps
 
@@ -28,10 +26,7 @@ def _setupAtlasThreadedJob():
 
     svcMgr.StatusCodeSvc.AbortOnError = False
 
-    nThreads = jps.ConcurrencyFlags.NumThreads()
     numStores = jps.ConcurrencyFlags.NumConcurrentEvents()
-    numAlgsInFlight = nThreads
-    numThreads = nThreads
 
     from StoreGate.StoreGateConf import SG__HiveMgrSvc
     svcMgr += SG__HiveMgrSvc("EventDataSvc")
@@ -42,7 +37,7 @@ def _setupAtlasThreadedJob():
 
 
     from GaudiHive.GaudiHiveConf import AlgResourcePool
-    arp=AlgResourcePool( OutputLevel = INFO );
+    arp=AlgResourcePool( OutputLevel = Constants.INFO )
     arp.TopAlg=["AthMasterSeq"] #this should enable control flow
     svcMgr += arp
 
@@ -69,7 +64,7 @@ def _setupAtlasThreadedJob():
 
     # enable timeline recording
     from GaudiHive.GaudiHiveConf import TimelineSvc
-    svcMgr += TimelineSvc( RecordTimeline = True, Partial = False );
+    svcMgr += TimelineSvc( RecordTimeline = True, Partial = False )
     
     #
     ## Setup SGCommitAuditor to sweep new DataObjects at end of Alg execute
diff --git a/Control/AthenaCommon/python/AtlasUnixGeneratorJob.py b/Control/AthenaCommon/python/AtlasUnixGeneratorJob.py
index c353f269495..3ce95e053b5 100755
--- a/Control/AthenaCommon/python/AtlasUnixGeneratorJob.py
+++ b/Control/AthenaCommon/python/AtlasUnixGeneratorJob.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 ## @file AtlasUnixGeneratorJob.py
 ## @brief py-module to configure the Athena AppMgr for generator (UNIX) jobs
@@ -7,7 +7,7 @@
 ###############################################################
 
 def _setupAtlasUnixGeneratorJob():
-    import AtlasUnixStandardJob
+    import AtlasUnixStandardJob    # noqa: F401
     from AppMgr import theApp
     from AppMgr import ServiceMgr as svcMgr
 
diff --git a/Control/AthenaCommon/python/AtlasUnixStandardJob.py b/Control/AthenaCommon/python/AtlasUnixStandardJob.py
index af0b1ea4c3c..f7a680519f5 100755
--- a/Control/AthenaCommon/python/AtlasUnixStandardJob.py
+++ b/Control/AthenaCommon/python/AtlasUnixStandardJob.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 ## @file AtlasUnixStandardJob.py
 ## @brief py-module to configure the Athena AppMgr for standard (UNIX) jobs
@@ -10,8 +10,7 @@ def _setupAtlasUnixStandardJob():
     from AppMgr import theApp
     from AppMgr import ServiceMgr as svcMgr
 
-    import SystemOfUnits as Units
-    from Constants import VERBOSE, DEBUG, INFO, ERROR
+    from Constants import INFO
 
     ## basic Gaudi services
     import GaudiSvc.GaudiSvcConf as GaudiSvcConf
diff --git a/Control/AthenaCommon/python/CFElements.py b/Control/AthenaCommon/python/CFElements.py
index 032446791ef..0d24c59db75 100755
--- a/Control/AthenaCommon/python/CFElements.py
+++ b/Control/AthenaCommon/python/CFElements.py
@@ -216,4 +216,4 @@ class TestCF( unittest.TestCase ):
         self.assertIsNotNone( a1, "Could not find algorithm within the required nesting depth == 2" )
 
         a1 = findAlgorithm( self.top, "SomeAlg3", 2)
-        self.assertIsNotNone( a1 == None, "Could find algorithm evn if it is deep in sequences structure" )
+        self.assertIsNotNone( a1 is None, "Could find algorithm even if it is deep in sequences structure" )
diff --git a/Control/AthenaCommon/python/CfgMergerLib.py b/Control/AthenaCommon/python/CfgMergerLib.py
index 09d40571538..f0d05cf7e63 100644
--- a/Control/AthenaCommon/python/CfgMergerLib.py
+++ b/Control/AthenaCommon/python/CfgMergerLib.py
@@ -280,7 +280,6 @@ def analyze(oname="merge_candidates.pkl"):
     for k,v in histo.iteritems():
         msg.info ('#diffs: %3s  => #cfgs: %3s', k, v)
 
-    import os
     if os.path.splitext(oname)[1] == ".ascii":
         msg.info ("dumping report in ASCII [%s]", oname)
         with open(oname, "w") as ascii:
diff --git a/Control/AthenaCommon/python/ChapPy.py b/Control/AthenaCommon/python/ChapPy.py
index 14fadcb6aa1..ec002d2aa95 100755
--- a/Control/AthenaCommon/python/ChapPy.py
+++ b/Control/AthenaCommon/python/ChapPy.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # @file : ChapPy.py
 # @author: Sebastien Binet <binet@cern.ch> 
@@ -23,6 +23,7 @@ import os
 import commands
 import subprocess
 import time
+import types
 
 def dump( buf, stdout = sys.stdout ):
     """
@@ -65,14 +66,13 @@ class JobOptionsCmd( JobOptions ):
     def __init__( self, cmds = [] ):
 
         # massaging of input variables
-        if type(cmds) == type(""):
+        if isinstance(cmds, types.StringType):
             cmds = [ cmds ]
             pass
-        if type(cmds) != type([]):
+        if not isinstance(cmds, types.ListType):
             cmds = [ cmds ]
             pass
-        fileName = None
-        
+
         JobOptions.__init__( self, fileName = None )
         self.cmds    = cmds
         self.tmpFile = NamedTemporaryFile( suffix = ".py" )
@@ -97,7 +97,6 @@ class JobOptionsCmd( JobOptions ):
     
     pass # JobOptionsCmd
 
-from tempfile import NamedTemporaryFile
 class Athena( object ):
 
     class Options:
@@ -122,9 +121,8 @@ class Athena( object ):
 
         ## check that we are not called/constructed from a normal Athena job
         if os.path.basename( sys.argv[0] ) == "athena.py":
-            raise RuntimeError, \
-                  "This is not a normal Athena job !! "\
-                  "Run with 'chappy.py myjob.py' instead !"
+            raise RuntimeError("This is not a normal Athena job !! "
+                               "Run with 'chappy.py myjob.py' instead !")
         
         self.bin          = None
         self.cmdOptions   = cmdOptions
@@ -187,7 +185,7 @@ class Athena( object ):
         
         sc, out = commands.getstatusoutput( "which athena.py" )
         if sc != 0:
-            raise RuntimeError, "Could not fetch athena.py executable: %s" % out
+            raise RuntimeError("Could not fetch athena.py executable: %s" % out)
         else:
             self.bin = os.path.realpath(os.path.expandvars(out))
             pass
@@ -195,12 +193,12 @@ class Athena( object ):
         # prepare logFile
         try:
             self.logFile.truncate(0)
-        except IOError,err:
+        except IOError:
             pass
 
         try:
             self.logFile.seek(0)
-        except IOError,err:
+        except IOError:
             pass
 
         # build the command
@@ -224,7 +222,7 @@ class Athena( object ):
         
         # build the jobOptions command line
         cmd.extend( [ jobO.name() for jobO in self.jobOptions
-                                  if jobO.name() != None ] )
+                                  if jobO.name() is not None ] )
 
         # add AthAppMgr commands
         if isinstance( self.EvtMax, int ):
@@ -238,7 +236,7 @@ class Athena( object ):
                               env = env )
         monitor.write(" :::running [")
         monitor.flush()
-        while p.poll() == None:
+        while p.poll() is None:
             monitor.write(".")
             monitor.flush()
             time.sleep(5)
diff --git a/Control/AthenaCommon/python/ConcurrencyFlags.py b/Control/AthenaCommon/python/ConcurrencyFlags.py
index a4ebbf3b3ac..252df2f3d69 100644
--- a/Control/AthenaCommon/python/ConcurrencyFlags.py
+++ b/Control/AthenaCommon/python/ConcurrencyFlags.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 #=======================================================================
 # File:   AthenaCommon/python/ConcurrencyFlags.py
@@ -51,7 +51,7 @@ class NumThreads(JobProperty):
 
     def _do_action(self):
         try:
-            import GaudiHive
+            import GaudiHive  # noqa: F401
         except ImportError:
             from Logging import log
             log.fatal("GaudiHive not in release - can't use --threads parameter")
@@ -76,7 +76,7 @@ class NumConcurrentEvents(JobProperty):
 
     def _do_action(self):
         try:
-            import GaudiHive
+            import GaudiHive  # noqa: F401
         except ImportError:
             from Logging import log
             log.fatal("GaudiHive not in release - can't use --concurrent-events parameter")
diff --git a/Control/AthenaCommon/python/Configurable.py b/Control/AthenaCommon/python/Configurable.py
index 213e05f0a52..068af449f97 100755
--- a/Control/AthenaCommon/python/Configurable.py
+++ b/Control/AthenaCommon/python/Configurable.py
@@ -1,10 +1,10 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/Configurable.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
 # Author: Martin Woudstra (Martin.Woudstra@cern.ch)
 
-import copy, types, os, weakref,sys
+import copy, types, os, weakref
 from AthenaCommon import ConfigurableMeta
 
 # Note: load iProperty etc. from GaudiPython only as-needed
@@ -92,7 +92,6 @@ class Configurable( object ):
          except (IndexError,TypeError):
             raise TypeError( 'no "name" argument while instantiating "%s"' % cls.__name__ )
 
-      argname = name
       if name == Configurable.DefaultName:
        # select either conventional name, or the type of the class
          if hasattr( cls, 'DefaultedName' ):
@@ -105,11 +104,11 @@ class Configurable( object ):
 
     # close backdoor access to otherwise private subalgs/tools
       if 0 <= name.find( '.' ):
-         raise NameError( '"%s": Gaudi name indexing with "." to private configurables not '\
+         raise NameError( '"%s": Gaudi name indexing with "." to private configurables not '
                           'allowed, as it leads to uncheckable backdoors' % name )
 
       if 0 <= name.find( '/' ):
-         raise NameError( '"%s": type separator "/" no allowed in component name, '\
+         raise NameError( '"%s": type separator "/" no allowed in component name, '
                           'typename is derived from configurable instead' % name )
 
       #Uncomment the following line for debugging:
@@ -179,7 +178,7 @@ class Configurable( object ):
       conf = object.__new__( cls )
 
     # ... python convention says to silently return, if __new__ fails ...
-      if conf == None:
+      if conf is None:
          return
 
     # ... initialize it
@@ -313,7 +312,7 @@ class Configurable( object ):
                log.error( 'attempt to add a duplicate (%s.%s) ... dupe ignored' % (joname or self.name(),ccjo) )
                break
          else:
-            if index == None:
+            if index is None:
                self.__children.append( cc )
             else:
                self.__children.insert( index, cc )
@@ -366,7 +365,7 @@ class Configurable( object ):
       if type(items) != list and type(items) != tuple:
          items = [ items ]
 
-      self.__children = [ e for e in self.__children if not e in items ]
+      self.__children = [ e for e in self.__children if e not in items ]
 
    def removeAll( self ):
       self.remove( self.__children )
@@ -492,7 +491,7 @@ class Configurable( object ):
     # allow again changes to be made
       import sys, traceback
       stack = traceback.extract_stack( sys._getframe(1), 1 )
-      log.warning( 'unlock() called on configurable "%s" in %s', self.getJobOptName(), stack[0][0] );
+      log.warning( 'unlock() called on configurable "%s" in %s', self.getJobOptName(), stack[0][0] )
       self._flags &= ~self._fIsLocked
 
     # note that unlock() does not unlock the children; do that individually
@@ -544,7 +543,7 @@ class Configurable( object ):
 
     # defaults from C++
       for k,v in cls._properties.items():
-         if not k in c.__dict__ and hasattr( v, 'default' ):
+         if k not in c.__dict__ and hasattr( v, 'default' ):
             c.__dict__[ k ] = v.default
 
       return c.__dict__
@@ -617,7 +616,7 @@ class Configurable( object ):
 
       import OldStyleConfig
       for svc in svcs:
-         handle = OldStyleConfig.Service( svc )
+         handle = OldStyleConfig.Service( svc )  # noqa: F841
        # services should be configurables as well, but aren't for now
        # handle.setup()
 
@@ -629,7 +628,7 @@ class Configurable( object ):
       dlls = self.getDlls()
       if not dlls:
          dlls = []
-      elif type(dlls) == types.StringType:
+      elif isinstance(dlls, types.StringType):
          dlls = [ dlls ]
 
       from AppMgr import theApp
diff --git a/Control/AthenaCommon/python/ConfigurableDb.py b/Control/AthenaCommon/python/ConfigurableDb.py
index 6123eb2a42e..716d4d4f6b8 100755
--- a/Control/AthenaCommon/python/ConfigurableDb.py
+++ b/Control/AthenaCommon/python/ConfigurableDb.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/ConfigurableDb.py
 # Author: Sebastien Binet (binet@cern.ch)
@@ -97,12 +97,12 @@ class _CfgDb( dict ):
               'module'  : module,
               'lib'     : lib }
 
-      if self.has_key( configurable ):
+      if configurable in self:
        # check if it comes from the same library...
          if cfg['lib'] != self[configurable]['lib']:
             self.msg.verbose( "dup!! [%s] p=%s m=%s lib=%s",
                           configurable, package, module, lib )
-            if self._duplicates.has_key(configurable):
+            if configurable in self._duplicates:
                self._duplicates[configurable] += [ cfg ]
             else:
                self._duplicates[configurable]  = [ cfg ]
@@ -143,11 +143,9 @@ def loadConfigurableDb():
    Configurables available in the release
    """
 
-   import os, sys
-   from glob import glob
+   import os
    from os.path import join as path_join
-   from fnmatch import fnmatch as _fnmatch
-   
+
    global cfgDb
 
    cfgDb.msg.debug( "loading confDb files..." )
@@ -175,8 +173,8 @@ def loadConfigurableDb():
          except Exception, err:
             import traceback
             traceback.print_exc()
-            log.warning( "Could not load file [%s] !", confDb )
-            log.warning( "Reason: %s", err )
+            cfgDb.msg.warning( "Could not load file [%s] !", confDb )
+            cfgDb.msg.warning( "Reason: %s", err )
          nFiles += 1
    cfgDb.msg.debug( "loading confDb files... [DONE]" )
    nPkgs = len( set([k['package'] for k in cfgDb.values()]) )
diff --git a/Control/AthenaCommon/python/ConfigurableMeta.py b/Control/AthenaCommon/python/ConfigurableMeta.py
index e16f4172074..75ba5fce614 100755
--- a/Control/AthenaCommon/python/ConfigurableMeta.py
+++ b/Control/AthenaCommon/python/ConfigurableMeta.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/ConfigurableMeta.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -37,7 +37,7 @@ class ConfigurableMeta( type ):
     # it is safe to assume that any such vars are python private ones)
       newclass = type.__new__( self, name, bases, dct )
 
-      if not 'AthenaCommon' in newclass.__module__:
+      if 'AthenaCommon' not in newclass.__module__:
        # check for required methods and the right number of arguments
        # meths = { 'getServices'   : 1,    # retrieve list of services to configure
          meths = { 'getDlls'       : 1,    # provide list of Dlls to load
diff --git a/Control/AthenaCommon/python/ConfigurationCleanup.py b/Control/AthenaCommon/python/ConfigurationCleanup.py
index 09a53efe788..28395a32bfb 100644
--- a/Control/AthenaCommon/python/ConfigurationCleanup.py
+++ b/Control/AthenaCommon/python/ConfigurationCleanup.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/ConfigurationCleanup.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -42,7 +42,8 @@ def Cleanse():
    pycomps_dumpname = 'pycomponents_dump.pickle'
    f = open( pycomps_dumpname, 'wb' )
    pickle.dump( AthenaPython.Configurables.PyComponents.instances, f )
-   f.flush(); f.close()
+   f.flush()
+   f.close()
    del f, AthenaPython.Configurables, pickle
 
    def _is_special (c):
@@ -193,7 +194,7 @@ def Cleanse():
          continue
 
       try:
-         if issubclass( o, JobProperty ) and not o is JobProperty:
+         if issubclass( o, JobProperty ) and o is not JobProperty:
             stillThere.append( o )
             continue
       except TypeError:
diff --git a/Control/AthenaCommon/python/ConfiguredFactory.py b/Control/AthenaCommon/python/ConfiguredFactory.py
index bbbf6c08b6c..d77246b57bf 100644
--- a/Control/AthenaCommon/python/ConfiguredFactory.py
+++ b/Control/AthenaCommon/python/ConfiguredFactory.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 __author__ = 'Martin Woudstra <martin.woudstra@cern.ch>'
 
@@ -12,7 +12,7 @@ from GaudiKernel.GaudiHandles import \
 
 from Configurable import Configurable
 import ConfigurableDb
-from AppMgr import ToolSvc,ServiceMgr
+from AppMgr import ToolSvc, ServiceMgr  # noqa: 401
 from Logging import logging
 
 
@@ -281,8 +281,7 @@ class PropertyStack(object):
 
     def pop(self):
         self._names.pop()
-        fullPropName = self._props.pop()
-##        print "Removing from property stack %i: %s" % (self.depth()+1,fullPropName)
+        self._props.pop()
 
     def depth(self):
         return len(self._props)
@@ -674,7 +673,6 @@ class ConfiguredFactory(object):
 
     def _resolveAllProperties(self,conf,indent="",propStack=None):
 
-        confName = conf.getName()
         defaultProps = conf.getDefaultProperties()
         for name,value in defaultProps.items():
             # skip non-configurables, since they don't need to be resolved
@@ -1180,7 +1178,6 @@ class ConfiguredFactory(object):
         log = self.logger()
         nConfig = self.numberOfConfigurables()
         nInstances = self.numberOfInstances()
-        sepLine = 80*"-";
         lines = [ "%d configurables were declared, %d instantiated (indicated by *):" % (nConfig, nInstances) ]
         # print in alphabetic order by name
         names = self._availableConfigurables.keys()
@@ -1189,7 +1186,6 @@ class ConfiguredFactory(object):
             c = self._availableConfigurables[n]
             lines.append( c.shortDescription(n) )
         lines.append( "end of list of declared configurables" )
-#        lines.append( sepLine )
         log.info( os.linesep.join(lines) )
 
 
diff --git a/Control/AthenaCommon/python/DumpProperties.py b/Control/AthenaCommon/python/DumpProperties.py
index 5e70498c1e2..d914322c3f9 100755
--- a/Control/AthenaCommon/python/DumpProperties.py
+++ b/Control/AthenaCommon/python/DumpProperties.py
@@ -1,11 +1,12 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/DumpProperties.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
 
 """Dump all properties from Gaudi objects in a given namespace."""
 
-import os, sys, re, types
+import os
+import sys
 import GaudiPython
 
 
@@ -27,11 +28,11 @@ log = logging.getLogger( 'DumpProperties' )
 def _printFromLookup( ns, listing, lookup, extra, klass ):
    """<internal>"""
  
-   if not ns.has_key( 'theApp' ):
+   if 'theApp' not in ns:
       log.error( 'given namespace does not contain "theApp"' )
       return
 
-   if not ns.has_key( lookup ):
+   if lookup not in ns:
       log.error( 'given namespace does not contain "%s" lookup', lookup )
       return
 
@@ -47,7 +48,7 @@ def _printFromLookup( ns, listing, lookup, extra, klass ):
    if extra and type(extra) != list:
       extra = getattr( app, extra )
 
-   extra = [ e for e in extra if not e in listing ]
+   extra = [ e for e in extra if e not in listing ]
 
    lookup = ns[ lookup ]
    for name in listing:
@@ -105,7 +106,7 @@ def dump( opt = [ 'set' ], ns = None ):
 'all', or a list of a combination of these. The given namespace must contain the
 application manager."""
 
-   if ns == None:
+   if ns is None:
       import __main__
       ns = __main__.__dict__ 
 
@@ -135,7 +136,7 @@ def dumpSet( ns = None ):
    """Dump all Gaudi objects that have had their properties set. The namespace must
 contain the application manager."""
 
-   if ns == None:
+   if ns is None:
       import __main__
       ns = __main__.__dict__
 
@@ -147,7 +148,7 @@ contain the application manager."""
 def dumpAlgorithms( ns = None ):
    """Dump all algorithm properties. The namespace must contain the application mgr."""
 
-   if ns == None:
+   if ns is None:
       import __main__
       ns = __main__.__dict__
 
@@ -157,7 +158,7 @@ def dumpAlgorithms( ns = None ):
 def dumpServices( ns = None ):
    """Dump all service properties. The namespace must contain the application mgr."""
 
-   if ns == None:
+   if ns is None:
       import __main__
       ns = __main__.__dict__
 
diff --git a/Control/AthenaCommon/python/GlobalFlags.py b/Control/AthenaCommon/python/GlobalFlags.py
index 493ad9d4a6a..1d0b5308b9b 100755
--- a/Control/AthenaCommon/python/GlobalFlags.py
+++ b/Control/AthenaCommon/python/GlobalFlags.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 ###############################################################################
 ##
@@ -202,7 +202,7 @@ class GlobalFlags:
         def is_ctb (cls):
             # stop if any flags have not been set yet
             if not cls._beenSet:
-                raise RuntimeError, 'ERROR : GlobalFlags.%s has not been set!' % cls.__name__
+                raise RuntimeError('ERROR : GlobalFlags.%s has not been set!' % cls.__name__)
             return cls._flag_ctbh6 | cls._flag_ctbh8
         is_ctb = classmethod(is_ctb)
 
@@ -253,19 +253,19 @@ class GlobalFlags:
                     def set (self):
                         # stop if already set
                         if self._clsObj._beenSet:
-                            raise RuntimeError, 'ERROR : GlobalFlags.%s has been already set!' % self._clsObj.__name__
+                            raise RuntimeError('ERROR : GlobalFlags.%s has been already set!' % self._clsObj.__name__)
                         # set flags true
                         setattr(self._clsObj, self._flagName, True)
                         self._clsObj._beenSet = True
-                        raise RuntimeError, "ERROR GlobalFlags.set_%s() deprecated ! Use globalflags.%s.set_Value_and_Lock(blah) instead !" % (self._clsObj.__name__+"."+self._flagName[6:],self._clsObj.__name__)
+                        raise RuntimeError("ERROR GlobalFlags.set_%s() deprecated ! Use globalflags.%s.set_Value_and_Lock(blah) instead !" % (self._clsObj.__name__+"."+self._flagName[6:],self._clsObj.__name__))
                         # setting at the same time jobproperties value 
                         data={'JobProperties.Global':{self._clsObj._name:self._flagName.replace('_flag_','')}}   
                         jobproperties.set_JobProperties(data)
                     def is_xyz (self):
-                        raise RuntimeError,"ERROR GlobalFlags.is_%s() deprecated ! Use if globalflags.%s == blah instead !" % (self._flagName[6:],self._clsObj.__name__)
+                        raise RuntimeError("ERROR GlobalFlags.is_%s() deprecated ! Use if globalflags.%s == blah instead !" % (self._flagName[6:],self._clsObj.__name__))
                         # stop if any flags have not been set yet
                         if not self._clsObj._beenSet:
-                            raise RuntimeError, 'ERROR : GlobalFlags.%s has not been set!' % self._clsObj.__name__
+                            raise RuntimeError('ERROR : GlobalFlags.%s has not been set!' % self._clsObj.__name__)
                         return getattr(self._clsObj, self._flagName)
                     
                 _tmpC = _TmpC(_classObj,_attr)
diff --git a/Control/AthenaCommon/python/Include.py b/Control/AthenaCommon/python/Include.py
index 2c5aac2b12f..6081b56bf06 100755
--- a/Control/AthenaCommon/python/Include.py
+++ b/Control/AthenaCommon/python/Include.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/Include.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -7,7 +7,7 @@
 JOBOPTSEARCHPATH envar and globally executed. If requested, files will be
 traced. Note, however, that this option interferes with pdb and trace."""
 
-import os, sys, re, fnmatch, string
+import os, sys, re, fnmatch
 from Utils.unixtools import FindFile
 
 
@@ -17,7 +17,7 @@ __author__  = 'Wim Lavrijsen (WLavrijsen@lbl.gov)'
 
 __all__ = [ 'include', 'marker', 'lineMarker', 'fidMarker',
             'callMarker', 'returnMarker', 'activeMarker', 'silentMarker',
-            'tracedMarker', 'tracePattern' ]
+            'tracedMarker' ]
 
 marker       = ' -+-'
 __marker__   = ' -+-'
@@ -225,7 +225,7 @@ class Include( object ):
       if not ( fn and self._doTrace( fn ) ):
          return self._trace_include
 
-      if not _filecache.has_key( fn ):
+      if fn not in _filecache:
        # wait until importing of the module is done to minimize pollution
          f = frame.f_back
          while f is not None:
diff --git a/Control/AthenaCommon/python/JobProperties.py b/Control/AthenaCommon/python/JobProperties.py
index 751de3c14f5..2b19ec588ba 100755
--- a/Control/AthenaCommon/python/JobProperties.py
+++ b/Control/AthenaCommon/python/JobProperties.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 #=======================================================================
 # File: JobProperties/python/JobProperties.py
@@ -23,8 +23,8 @@ __all__ = [ "JobProperties"]
 #=======================================================================
 # imports
 #=======================================================================
-import re, os, pickle, pprint 
-import Constants, Logging
+import re, os, pickle, pprint, types
+import Logging
 
 #=======================================================================
 def _isCompatible( allowedTypes, value ):
@@ -74,7 +74,7 @@ class _JobPropertyMeta(type):
      # StoredValue type check
         try:
             sv = dct[ 'StoredValue' ]
-            if sv != None and not _isCompatible( dct[ 'allowedTypes' ], sv ):
+            if sv is not None and not _isCompatible( dct[ 'allowedTypes' ], sv ):
                 raise TypeError(
                     'type of StoredValue (%s) not in allowedTypes (%s)' % 
                     (type(sv).__name__,dct[ 'allowedTypes' ])
@@ -85,7 +85,7 @@ class _JobPropertyMeta(type):
      # StoredValue value check
         try:
             sv = dct[ 'StoredValue' ]
-            if sv != None and dct[ 'allowedValues' ] and sv not in dct[ 'allowedValues' ]:
+            if sv is not None and dct[ 'allowedValues' ] and sv not in dct[ 'allowedValues' ]:
                 raise TypeError(
                     'value of StoredValue (%s) not in allowedValues (%s)' % 
                     (str(sv),dct[ 'allowedValues' ])
@@ -140,7 +140,7 @@ class JobProperty(object):
             self.__name__=self.__class__.__name__
             self._context_name=context+'.'+self.__class__.__name__
         else:
-            self._log.error("There is already an instance of %s at %s ",\
+            self._log.error("There is already an instance of %s at %s ",
                             self.__class__.__name__, context_name)
             raise RuntimeError('JobProperties: JobProperty:: __init__()')
 
@@ -173,7 +173,8 @@ class JobProperty(object):
         return self.StoredValue
         
 
-    def is_locked(self): return self._locked
+    def is_locked(self):
+        return self._locked
     
     def _do_action(self):
         """ A place-holder for actions to be taken at the time 
@@ -245,7 +246,7 @@ class JobProperty(object):
                         self.set_On()
                     elif _isCompatible(self.allowedTypes, n_value):
                         self.__dict__[name] = n_value
-                        if isinstance(n_value, bool) and n_value == False:
+                        if isinstance(n_value, bool) and n_value is False:
                             self.set_Off() 
                         else:
                             self.set_On()
@@ -294,7 +295,7 @@ class JobProperty(object):
            otherwise it gives None. 
         """
         obj_p=object.__getattribute__(self, 'StoredValue')
-        if type(obj_p)==type(True):
+        if isinstance(obj_p, types.BooleanType):
             return  obj_p  & self.statusOn 
         else: 
             if self.statusOn: 
@@ -518,7 +519,8 @@ class JobPropertyContainer (object):
         else: 
             return self.print_JobProperties('print_v') 
 
-    def is_locked(self): return self._locked
+    def is_locked(self):
+        return self._locked
     
     def help(self):
         """ Prints the documentation generated with the JobProperty 
diff --git a/Control/AthenaCommon/python/KeyStore.py b/Control/AthenaCommon/python/KeyStore.py
index 57dabda9701..6d95ec3926d 100644
--- a/Control/AthenaCommon/python/KeyStore.py
+++ b/Control/AthenaCommon/python/KeyStore.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # @file: AthenaCommon/python/KeyStore.py
 # @author: Sebastien Binet (binet@cern.ch)
@@ -68,7 +68,7 @@ class CfgItemList( object ):
 
     def __new__(cls, *p, **kw):
 
-        if not kw.has_key('name'):
+        if 'name' not in kw:
             if len(p) == 0: kw['name'] = cls.__slots__['_name']
             else:           kw['name'] = p[0]
 
@@ -104,10 +104,10 @@ class CfgItemList( object ):
         if not self._items:    self._items    = []
 
         items = []
-        if kwargs.has_key('items'):
+        if 'items' in kwargs:
             items = kwargs['items']
 
-        if kwargs.has_key('allowWildCard'):
+        if 'allowWildCard' in kwargs:
             self._allowWildCard = kwargs['allowWildCard']
             
         msg.verbose( "create [%s] items = %r allowWildCard = %s",
@@ -153,8 +153,6 @@ class CfgItemList( object ):
         if not type(itemLists) in (list,tuple):
             itemLists = ( itemLists, )
 
-        name = self._name
-
         for cfg in itemLists:
             # prevent type mismatches
             if not isinstance( cfg, CfgItemList ):
@@ -230,7 +228,7 @@ class CfgItemList( object ):
         if not type(items) in ( types.ListType, types.TupleType ):
             items = [ items ]
 
-        self._children = [ e for e in self._children if not e in items ]
+        self._children = [ e for e in self._children if e not in items ]
 
     def removeAll( self ):
         self.remove( self._children )
@@ -252,7 +250,7 @@ class CfgItemList( object ):
         for item in self._items:
             cppType = item.split("#")[0]
             sgKey   = item.replace( cppType+"#", '' )
-            if props.has_key( cppType ):
+            if cppType in props:
                 if sgKey not in props[cppType]:
                     props[cppType].append( sgKey )
             else:
@@ -417,7 +415,7 @@ class CfgKeyStore( object ):
 
     def __new__(cls, *p, **kw):
 
-        if not kw.has_key('name'):
+        if 'name' not in kw:
             if len(p) == 0: kw['name'] = cls.__slots__['_name']
             else:           kw['name'] = p[0]
 
@@ -477,21 +475,21 @@ class CfgKeyStore( object ):
     ##
 
     def __getitem__( self, k ):
-        if not k in CfgKeyStore.__slots__['Labels']:
-            raise KeyError, "key [%s] is not an allowed one: %s" % \
-                  ( k, CfgKeyStore.__slots__['Labels'] )
+        if k not in CfgKeyStore.__slots__['Labels']:
+            raise KeyError("key [%s] is not an allowed one: %s" %
+                           ( k, CfgKeyStore.__slots__['Labels'] ))
         root = self._items
         if k.count('stream') > 0:
             root = getattr( root, self._name+'_transient' )
         try:
             return getattr( root, self._name+"_"+k )
         except AttributeError,err:
-            raise KeyError, str(err)
+            raise KeyError(str(err))
     
     def __setitem__( self, k, v ):
-        if not k in CfgKeyStore.__slots__['Labels']:
-            raise KeyError, "key [%s] is not an allowed one: %s" % \
-                  ( k, CfgKeyStore.__slots__['Labels'] )
+        if k not in CfgKeyStore.__slots__['Labels']:
+            raise KeyError("key [%s] is not an allowed one: %s" %
+                           ( k, CfgKeyStore.__slots__['Labels'] ))
         root = self._items
         if k.count('stream') > 0:
             root = getattr( root, self._name+'_transient' )
@@ -505,7 +503,7 @@ class CfgKeyStore( object ):
                 return super(CfgKeyStore, self).__getattribute__(k)
             return super(CfgKeyStore, self).__getattribute__(k)
         except KeyError,err:
-            raise AttributeError,str(err)
+            raise AttributeError(str(err))
 
     def __setattr__( self, k, v ):
         if k in CfgKeyStore.__slots__['Labels']:
@@ -528,7 +526,7 @@ class CfgKeyStore( object ):
         return zip( self.keys(), self.values() )
     
     def clear(self, label = None):
-        if label != None:
+        if label is not None:
             self[label].clear()
         else:
             for c in self._items.children():
@@ -682,10 +680,10 @@ def keystore_diff (ref, chk, labels=None, ofile=None):
             diff.append ("- len(ref[%s]) == %i" % (label,len(ref_content)))
             diff.append ("+ len(chk[%s]) == %i" % (label,len(chk_content)))
         for r in ref_content:
-            if not r in chk_content:
+            if r not in chk_content:
                 diff.append ("- ref[%s] : %s" % (label, r))
         for c in chk_content:
-            if not c in ref_content:
+            if c not in ref_content:
                 diff.append ("+ chk[%s] : %s" % (label, c))
     if len(diff) == 0:
         return ""
diff --git a/Control/AthenaCommon/python/ObjectBrowser.py b/Control/AthenaCommon/python/ObjectBrowser.py
index 07e588cd60a..fed6dfb25b8 100755
--- a/Control/AthenaCommon/python/ObjectBrowser.py
+++ b/Control/AthenaCommon/python/ObjectBrowser.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/share/ObjectBrowser.py
 # Author: Wim Lavrijsen (LBNL, WLavrijsen@lbl.gov)
@@ -67,19 +67,19 @@ class TopTreeItem( ibrowser.ObjectTreeItem ):
 
 
 def initTreeItemsDispatch():
-   if gmod != None:
+   if gmod is not None:
     ## add Gaudi specific tree items
-      if not ibrowser.dispatch.has_key( gmod.iAlgorithm ):
+      if gmod.iAlgorithm not in ibrowser.dispatch:
          ibrowser.dispatch[ gmod.iAlgorithm ] = GaudiAlgTypeTreeItem
 
-      if not ibrowser.dispatch.has_key( gmod.iService ):
+      if gmod.iService not in ibrowser.dispatch:
          ibrowser.dispatch[ gmod.iService ] = GaudiSvcTypeTreeItem
 
 
 class Browser( Tkinter.Frame ):
    def __init__( self, master = None ):
     # setup Tk as necessary
-      if master == None:
+      if master is None:
          master = Tkinter.Tk()
 
     # setup base
@@ -98,7 +98,7 @@ class Browser( Tkinter.Frame ):
       dct = sys.modules[ '__main__' ].__dict__
 
       algs, svcs = {}, {}
-      if gmod != None:
+      if gmod is not None:
          algs = self.select( dct, gmod.iAlgorithm )
          svcs = self.select( dct, gmod.iService )
 
diff --git a/Control/AthenaCommon/python/PhysicalConstants.py b/Control/AthenaCommon/python/PhysicalConstants.py
index 10e16b6dfc6..3530887182e 100755
--- a/Control/AthenaCommon/python/PhysicalConstants.py
+++ b/Control/AthenaCommon/python/PhysicalConstants.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/share/PhysicalConstants.py
 # Author: Wim Lavrijsen (LBNL, WLavrijsen@lbl.gov)
@@ -41,7 +41,7 @@
 #          and pressure; also added Gas threshold.
 # -----
 
-from SystemOfUnits import *
+from SystemOfUnits import henry, eplus, MeV, joule, s, m, kelvin, atmosphere, g, mg, cm3, mole
 
 #
 #
diff --git a/Control/AthenaCommon/python/PoolInputFileListBase.py b/Control/AthenaCommon/python/PoolInputFileListBase.py
index b0de7815ea1..23011267493 100644
--- a/Control/AthenaCommon/python/PoolInputFileListBase.py
+++ b/Control/AthenaCommon/python/PoolInputFileListBase.py
@@ -1,26 +1,27 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 ##
 ## @file AthenaCommon/python/PoolInputFileListBase.py
 ## @brief base class for POOL input file list properties
 ##
+
+import os
+import sys
 from JobProperties import JobProperty
+
 class PoolInputFileListBase(JobProperty):
     """base class for POOL input file list properties. Its call back will register each file in the list using pool_insertFileToCatalog"""
     allowedTypes = ['list']
     def _do_action(self):
         #first look if we have a POOL_CATALOG around
-        import os
-        pc_around = (None != os.getenv("POOL_CATALOG"))
-        if False == pc_around :
+        pc_around = (os.getenv("POOL_CATALOG") is not None)
+        if not pc_around :
             #may be there is a catalog file in the way
-            import os.path
             pc_path = os.path.abspath("PoolFileCatalog.xml")
             if os.path.exists(pc_path):
                 pc_around = True
             os.putenv("POOL_CATALOG", "file:" + pc_path)
         for filePath in self.get_Value() :
-            import os, sys
             #if there is a pool catalog check whether it contains our filePath 1st
             if (pc_around) :
                 import commands
diff --git a/Control/AthenaCommon/python/PropertiesManip.py b/Control/AthenaCommon/python/PropertiesManip.py
index 894cb08cf19..a0218e001c3 100755
--- a/Control/AthenaCommon/python/PropertiesManip.py
+++ b/Control/AthenaCommon/python/PropertiesManip.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/PropertiesManip.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -35,7 +35,7 @@ def removeItemsFromList( owner, property, items ):
    if type(items) != list and type(items) != tuple:
       items = [ items ]
 
-   current = getattr( owner, property )
+   current = getattr( owner, property )  # noqa: F841
    exec( 'owner.%s = [ e for e in current if not e in items ]' % property )
 
 
diff --git a/Control/AthenaCommon/python/PropertyProxy.py b/Control/AthenaCommon/python/PropertyProxy.py
index 6323ac1e4c7..cbf59a3e5e8 100755
--- a/Control/AthenaCommon/python/PropertyProxy.py
+++ b/Control/AthenaCommon/python/PropertyProxy.py
@@ -1,14 +1,11 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/PropertyProxy.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
 # Author: Martin Woudstra (Martin.Woudstra@cern.ch)
 
-import os, sys, weakref, copy
-try:
-   from GaudiKernel.GaudiHandles import *
-except ImportError:
-   from GaudiPython.GaudiHandles import *
+import os, weakref, copy, types
+from GaudiKernel.GaudiHandles import GaudiHandle, GaudiHandleArray
 
 # dictionary with configurable class : python module entries
 import ConfigurableDb
@@ -145,7 +142,7 @@ class PropertyProxy( object ):
          proptype = type( self.history[ obj ][ 0 ] )
 
     # check if type known; allow special initializer for typed instances
-      if proptype and proptype != type(None):
+      if proptype and not isinstance(proptype, types.NoneType):
         # check value itself
           value = _isCompatible( proptype, value )
 
@@ -163,9 +160,9 @@ class PropertyProxy( object ):
 
     # allow a property to be set if we're in non-default mode, or if it
     # simply hasn't been set before
-      if not obj._isInSetDefaults() or not obj in self.history:
+      if not obj._isInSetDefaults() or obj not in self.history:
        # by convention, 'None' for default is used to designate objects setting
-         if hasattr( self, 'default' ) and self.default == None:
+         if hasattr( self, 'default' ) and self.default is None:
             obj.__iadd__( value, self.descr )     # to establish hierarchy
          else:
             self.descr.__set__( obj, value )
@@ -251,7 +248,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
 
     # allow a property to be set if we're in non-default mode, or if it
     # simply hasn't been set before
-      if not obj._isInSetDefaults() or not obj in self.history:
+      if not obj._isInSetDefaults() or obj not in self.history:
          value = self.convertValueToBeSet( obj, value )
          # assign the value
          self.descr.__set__( obj, value )
diff --git a/Control/AthenaCommon/python/ResourceLimits.py b/Control/AthenaCommon/python/ResourceLimits.py
index 29156426c27..49906591663 100755
--- a/Control/AthenaCommon/python/ResourceLimits.py
+++ b/Control/AthenaCommon/python/ResourceLimits.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/ResourceLimits.py
 # Author: Grigori Rybkine (Grigori.Rybkine@rhul.ac.uk)
@@ -28,7 +28,7 @@ def _maxout( what, descr ):
                  soft == -1L and 'unlimited' or str(soft), )
       try:
          resource.setrlimit( what, (hard,hard) )
-      except ValueError, e:
+      except ValueError:
          if what != resource.RLIMIT_AS or hard != -1L: raise
          import platform
          if platform.architecture()[0] != '32bit': raise
@@ -45,7 +45,7 @@ def _max_32bit_address_space( soft, descr ):
                     str(hard),
                     str(soft), )
          resource.setrlimit( resource.RLIMIT_AS, (hard,hard) )
-      except ValueError, e:
+      except ValueError:
          hard -= _64MB
       else:
          log.debug( 'set soft %s limit to %s (was: %s)', descr,
diff --git a/Control/AthenaCommon/python/ServicesPythonize.py b/Control/AthenaCommon/python/ServicesPythonize.py
index 6c625f3211a..b4e31b87825 100755
--- a/Control/AthenaCommon/python/ServicesPythonize.py
+++ b/Control/AthenaCommon/python/ServicesPythonize.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/share/ServicesPythonize.py
 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
@@ -44,7 +44,7 @@ entries if no argument is given."""
 
    out.write( 'Dump of current catalogue entries:\n' )
    for client in allClients:
-      if what and not client in what:
+      if what and client not in what:
          continue
 
       out.write( '  %s\n' % client )
diff --git a/Control/AthenaCommon/python/ShellEscapes.py b/Control/AthenaCommon/python/ShellEscapes.py
index 316ab61d520..97fd071865c 100755
--- a/Control/AthenaCommon/python/ShellEscapes.py
+++ b/Control/AthenaCommon/python/ShellEscapes.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
 
 # File: AthenaCommon/python/ShellEscapes.py
 # Author: Wim Lavrijsen (LBNL, WLavrijsen@lbl.gov)
@@ -56,14 +56,14 @@ class ShellEscapes:
          cmd = value.text[:-1]
 
     # execute command, if any
-      if cmd != None:
+      if cmd is not None:
          args = string.split( cmd )
          exe = args[0]
 
        # special cases
          if exe == 'cd' and len(args) == 2:
             os.chdir( args[1] )
-            log.info( 'new directory: %s', AthConfig.shell.getcwd() )
+            log.info( 'new directory: %s', os.getcwd() )
             return
 
          if exe == 'help' and len(args) == 2:
@@ -72,14 +72,14 @@ class ShellEscapes:
             return
 
        # cache shell command
-         if not exe in _shellCommands:
+         if exe not in _shellCommands:
             log.debug( 'accepting executable "%s"', exe )
             if unixtools.which( exe ):
                _shellCommands.append( exe )
             else:
                exe = None
 
-         if exe != None:
+         if exe is not None:
             log.debug( 'executing shell command "%s"', cmd )
             os.system( cmd )
             return
-- 
GitLab