diff --git a/DDCore/python/dd4hepFactories.py b/DDCore/python/dd4hepFactories.py
index 21a590e1a1977e8763863a730d41f81a59d86435..4a77012e9b16e0dbf856523cb016f533e341caed 100755
--- a/DDCore/python/dd4hepFactories.py
+++ b/DDCore/python/dd4hepFactories.py
@@ -16,7 +16,7 @@ import sys
 import optparse
 import logging
 import errno
-from io import open
+import io
 
 logger = logging.getLogger(__name__)
 
@@ -42,7 +42,7 @@ class ComponentDumper:
 
   def readComponents(self, fname):
     logger.info('+== Search component file:  ' + fname)
-    file = open(fname, "r")
+    file = io.open(fname, "r")
     lines = file.readlines()
     dirname = os.path.dirname(fname)
     for line in lines:
diff --git a/DDDigi/python/dddigi.py b/DDDigi/python/dddigi.py
index 78de9303036e094244551e14a64ce0bf46a20194..609485cd600290e554a8f90bb396e846c5772403 100644
--- a/DDDigi/python/dddigi.py
+++ b/DDDigi/python/dddigi.py
@@ -203,14 +203,14 @@ def _kernel_terminate(self):
 
 
 def _default_adopt(self, action):
-  getattr(self, '__adopt')(action.get())
+  self.__adopt(action.get())
 # ---------------------------------------------------------------------------
 
 
 def _adopt_event_action(self, action):
   " Helper to convert DigiActions objects to DigiEventAction "
   proc = Interface.toEventAction(_get_action(action))
-  attr = getattr(self, '__adopt')
+  attr = self.__adopt
   attr(proc)
 # ---------------------------------------------------------------------------
 
@@ -218,7 +218,7 @@ def _adopt_event_action(self, action):
 def _adopt_container_processor(self, action, processor_argument):
   " Helper to convert DigiActions objects to DigiEventAction "
   parent = Interface.toContainerSequenceAction(_get_action(self))
-  attr = getattr(parent, 'adopt_processor')
+  attr = parent.adopt_processor
   proc = Interface.toContainerProcessor(_get_action(action))
   attr(proc, processor_argument)
 # ---------------------------------------------------------------------------
@@ -226,7 +226,7 @@ def _adopt_container_processor(self, action, processor_argument):
 
 def _adopt_segment_processor(self, action, processor_argument):
   " Helper to convert DigiActions objects to DigiEventAction "
-  attr = getattr(_get_action(self), '__adopt_segment_processor')
+  attr = _get_action(self).__adopt_segment_processor
   proc = Interface.toContainerProcessor(_get_action(action))
   attr(proc, processor_argument)
 # ---------------------------------------------------------------------------
@@ -245,7 +245,7 @@ def _adopt_sequence_action(self, name, **options):
 
 def _adopt_processor(self, action, containers):
   proc = Interface.toContainerProcessor(_get_action(action))
-  attr = getattr(_get_action(self), '__adopt_processor')
+  attr = _get_action(self).__adopt_processor
   attr(proc, containers)
 # ---------------------------------------------------------------------------
 
diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py
index 336ec54055cfc7ae083e403aec31a7750521fb77..69b39075b88c73e6c75941e6baec8b14bd5b8710 100644
--- a/DDG4/python/DDG4.py
+++ b/DDG4/python/DDG4.py
@@ -254,9 +254,9 @@ def _setup(obj):
     self.__adopt(action.get())
   _import_class('Sim', obj)
   o = getattr(current, obj)
-  setattr(o, '__adopt', getattr(o, 'adopt'))
-  setattr(o, 'adopt', _adopt)
-  setattr(o, 'add', _adopt)
+  o.__adopt = o.adopt
+  o.adopt = _adopt
+  o.add = _adopt
 
 
 def _setup_callback(obj):
@@ -264,8 +264,8 @@ def _setup_callback(obj):
     self.__adopt(action.get(), action.callback())
   _import_class('Sim', obj)
   o = getattr(current, obj)
-  setattr(o, '__adopt', getattr(o, 'add'))
-  setattr(o, 'add', _adopt)
+  o.__adopt = o.add
+  o.add = _adopt
 
 
 _setup_callback('Geant4ActionPhase')
@@ -443,7 +443,8 @@ class Geant4:
 
     \author  M.Frank
     """
-    ui_name = getattr(self.master(), 'UI')
+    # calls __getattr__ implicitly, which calls getKernelProperty
+    ui_name = self.master().UI
     return self.master().globalAction(ui_name)
 
   def addUserInitialization(self, worker, worker_args=None, master=None, master_args=None):
diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py
index 660e50a38cc092483ab64210da74d5897565517a..5d4b3a42b25af3b6cfbebb447e8f0535528b5de2 100644
--- a/DDG4/python/DDSim/DD4hepSimulation.py
+++ b/DDG4/python/DDSim/DD4hepSimulation.py
@@ -29,7 +29,7 @@ from DDSim.Helper.Gun import Gun
 from DDSim.Helper.UI import UI
 import argparse
 import logging
-from io import open
+import io
 
 logger = logging.getLogger('DDSim')
 
@@ -110,7 +110,7 @@ class DD4hepSimulation(object):
     if not self.steeringFile:
       return
     sFileTemp = self.steeringFile
-    exec(compile(open(self.steeringFile).read(), self.steeringFile, 'exec'), globs, locs)
+    exec(compile(io.open(self.steeringFile).read(), self.steeringFile, 'exec'), globs, locs)
     for _name, obj in locs.items():
       if isinstance(obj, DD4hepSimulation):
         self.__dict__ = obj.__dict__
diff --git a/DDG4/python/DDSim/Helper/Meta.py b/DDG4/python/DDSim/Helper/Meta.py
index 45b406da8d2131bd5c41568595a05f37cb311aed..c7db1cd59408b5404a2df5d1723c31ee31cd0e66 100644
--- a/DDG4/python/DDSim/Helper/Meta.py
+++ b/DDG4/python/DDSim/Helper/Meta.py
@@ -2,9 +2,9 @@
 
 from DDSim.Helper.ConfigHelper import ConfigHelper
 import datetime
+import io
 import os
 import logging
-from io import open
 
 logger = logging.getLogger(__name__)
 
@@ -76,12 +76,12 @@ class Meta(ConfigHelper):
 
     # steeringFile content
     if sim.steeringFile and os.path.exists(sim.steeringFile) and os.path.isfile(sim.steeringFile):
-      with open(sim.steeringFile) as sFile:
+      with io.open(sim.steeringFile) as sFile:
         runHeader["SteeringFileContent"] = sFile.read()
 
     # macroFile content
     if sim.macroFile and os.path.exists(sim.macroFile) and os.path.isfile(sim.macroFile):
-      with open(sim.macroFile) as mFile:
+      with io.open(sim.macroFile) as mFile:
         runHeader["MacroFileContent"] = mFile.read()
 
     # add command line
diff --git a/DDTest/python/test_import.py b/DDTest/python/test_import.py
index 40796d3d231fa7b92fdb6bdb2749520e5ede409c..7210895b9879a4f63f224ded869bb01c12c699d3 100644
--- a/DDTest/python/test_import.py
+++ b/DDTest/python/test_import.py
@@ -44,10 +44,10 @@ def test_module(moduleName):
     print(traceback.print_exc())
 
     if moduleName in ALLOWED_TO_FAIL:
-      warnings.warn(msg)
+      warnings.warn(msg, stacklevel=2)
       pytest.skip("WARN: " + msg)
     elif moduleName in GRAPHIC_MODULES:
-      warnings.warn(msg + "(Possibly due to system graphic libraries not present)")
+      warnings.warn(msg + "(Possibly due to system graphic libraries not present)", stacklevel=2)
       pytest.skip("WARN: " + msg + "(Possibly due to system graphic libraries not present)")
     else:
       pytest.fail("ERROR: " + msg)
diff --git a/etc/CreateParsers.py b/etc/CreateParsers.py
index 94273ce19cb3564f94d8e1f72aec31cfef33e6f9..b5908a49a4fe87017f879d28574426de49884937 100644
--- a/etc/CreateParsers.py
+++ b/etc/CreateParsers.py
@@ -13,8 +13,9 @@ python CreateParsers.py
 """
 
 from __future__ import absolute_import, unicode_literals
+import io
 import os
-from io import open
+
 
 LICENSE = """// $Id$
 //==========================================================================
@@ -75,7 +76,7 @@ IMPLEMENT_MAPPED_PARSERS(pair,%(type)s)
   fileContent = LICENSE + fileContent
   if os.path.exists(filename):
     os.remove(filename)
-  with open(filename, "w") as parseFile:
+  with io.open(filename, "w") as parseFile:
     parseFile.write(fileContent)
 
 
@@ -92,7 +93,7 @@ IMPLEMENT_STL_PARSER(%(cont)s,%(type)s)
   fileContent = LICENSE + fileContent
   if os.path.exists(filename):
     os.remove(filename)
-  with open(filename, "w") as parseFile:
+  with io.open(filename, "w") as parseFile:
     parseFile.write(fileContent)
 
 
@@ -110,7 +111,7 @@ IMPLEMENT_STL_MAP_PARSER(std::map,%(mtype)s,%(type)s)
   fileContent = LICENSE + fileContent
   if os.path.exists(filename):
     os.remove(filename)
-  with open(filename, "w") as parseFile:
+  with io.open(filename, "w") as parseFile:
     parseFile.write(fileContent)
 
 
diff --git a/examples/AlignDet/drivers/Shelf.py b/examples/AlignDet/drivers/Shelf.py
index df1ed6015a5855af2437e857263d5abcf2053928..462433e27920a0a3dd5f01b4e0fd63aaa3b64833 100644
--- a/examples/AlignDet/drivers/Shelf.py
+++ b/examples/AlignDet/drivers/Shelf.py
@@ -39,7 +39,7 @@ def detector_Shelf(description, det):
                      description.material('Carbon'))
   b_vol.setVisAttributes(description, book.vis)
   x, y, z = plane.x - book.x, plane.y, -plane.z + book.z
-  for n in range(book.number):
+  for _n in range(book.number):
     e_vol.placeVolume(b_vol, Position(x, y, z))  # noqa: F821
     z += 2 * book.z + book.getF('dz')
 
@@ -53,7 +53,7 @@ def detector_Shelf(description, det):
   phv.addPhysVolID('id', det.id)
   de.addPlacement(phv)
   x, y, z = 0, book.y + plane.y - 2 * plane.getF('dy'), 0
-  for n in range(plane.number):
+  for _n in range(plane.number):
     g_vol.placeVolume(e_vol, Position(x, y, z))  # noqa: F821
     y += plane.getF('dy')
   # ---Return detector element---------------------------------------------------------------------------------
diff --git a/examples/ClientTests/scripts/MiniTelGenerate.py b/examples/ClientTests/scripts/MiniTelGenerate.py
index c177f8ba77d1c74626a5cb898a69a63c177142e0..7197e163ca690295ea1940e962425bb29884cc05 100644
--- a/examples/ClientTests/scripts/MiniTelGenerate.py
+++ b/examples/ClientTests/scripts/MiniTelGenerate.py
@@ -33,7 +33,7 @@ def run():
     cmds = []
     if not args.runs:
       args.runs = 1
-    for i in range(int(args.runs)):
+    for _i in range(int(args.runs)):
       cmds.append(run)
     cmds.append('/ddg4/UI/terminate')
     m.ui.Commands = cmds
diff --git a/examples/ClientTests/scripts/MiniTelSetup.py b/examples/ClientTests/scripts/MiniTelSetup.py
index 6f0a0190434abe3055b1cb1dc707fc19146bbb90..14765f9c85cbce9405e582850d1a2429a1dc518c 100644
--- a/examples/ClientTests/scripts/MiniTelSetup.py
+++ b/examples/ClientTests/scripts/MiniTelSetup.py
@@ -41,8 +41,12 @@ class Setup(DDG4TestSetup.Setup):
           act.OutputLevel = output_level
     return self
 
-  def defineOutput(self, output='MiniTel_' + time.strftime('%Y-%m-%d_%H-%M')):
+  def defineOutput(self, output=None):
+    if output is None:
+      output = 'MiniTel_' + time.strftime('%Y-%m-%d_%H-%M')
     return DDG4TestSetup.Setup.defineOutput(self, output)
 
-  def defineEdm4hepOutput(self, output='MiniTel_' + time.strftime('%Y-%m-%d_%H-%M')):
+  def defineEdm4hepOutput(self, output=None):
+    if output is None:
+      output = 'MiniTel_' + time.strftime('%Y-%m-%d_%H-%M')
     return DDG4TestSetup.Setup.defineEdm4hepOutput(self, output)
diff --git a/examples/DDCodex/python/CODEX-b-alone.py b/examples/DDCodex/python/CODEX-b-alone.py
index 6e358c444f4b7cac4212d0b695a936ef3df4b2e7..df02245ca691c9dab2803378e035c7509491ad62 100755
--- a/examples/DDCodex/python/CODEX-b-alone.py
+++ b/examples/DDCodex/python/CODEX-b-alone.py
@@ -55,7 +55,7 @@ def run():
                         # direction=(0.866025,0,0.5),
                         position='(0,0,12650)')
   # position='(0,0,0)')
-  setattr(gun, 'print', True)
+  gun.print = True
   """
   gen =  DDG4.GeneratorAction(kernel,"Geant4InputAction/Input")
   # gen.Input = "Geant4EventReaderHepMC|"+