Uploaded image for project: 'RHEL Conversions'
  1. RHEL Conversions
  2. RHELC-588

Improve Python 2 and 3 compatibility

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Minor Minor
    • 1.0
    • None
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • 2
    • 2022-Q3

      Right now we are using if else condition for solving the compatibility issues with renamed modules between Python 2 & 3. For solving this is library called six, which we are already using somewhere, so why not use it for solving this too.

      This problem is mainly with mock from unittest, but I've spotted it with configparser too.

      Example of the change:

      # before
      if sys.version_info[:2] <= (2, 7):
         import mock  
      else:
         from unittest import mock
      
      # after
      six.add_move(six.MovedModule("mock", "mock", "unittest.mock"))
      from six.moves import mock
      

      https://six.readthedocs.io/

              ahosek@redhat.com Adam Hosek
              ahosek@redhat.com Adam Hosek
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: