Upgrade to Python 3.12

Proprietary

Migrate deprecated and removed APIs for Python 3.12 compatibility. This includes detecting usage of the removed imp module and other legacy modules that were removed in Python 3.12.

org.openrewrite.python.migrate.UpgradeToPython312
mod run . --recipe=org.openrewrite.python.migrate.UpgradeToPython312

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Upgrade to Python 3.11
  2. Replace datetime.utcnow() with datetime.now(UTC).replace(tzinfo=None)
  3. Replace datetime.utcfromtimestamp() with datetime.fromtimestamp(ts, UTC).replace(tzinfo=None)
  4. Replace deprecated calendar month constants with uppercase
  5. Change import
  6. Find deprecated imp module usage
  7. Find imports of the deprecated distutils.version module
  8. Find deprecated distutils module usage
  9. Replace pkgutil.find_loader() with importlib.util.find_spec()
  10. Replace pkgutil.get_loader() with importlib.util.find_spec()
  11. Find deprecated Path.link_to() usage
  12. Find modules removed in Python 3.12
  13. Find deprecated ssl.match_hostname()
  14. Find deprecated os.popen() usage
  15. Find deprecated os.spawn*() usage
  16. Find deprecated shutil.rmtree(onerror=...) parameter
  17. Replace sys.last_type / sys.last_value / sys.last_traceback with sys.last_exc
  18. Add the assert_ prefix to mock assertions that lack it
  19. Replace ~ on a bool with ~int()
  20. Find bitwise inversion ~ on a bool
  21. Find deprecated ByteString
  22. org.openrewrite.python.migrate.UpgradePythonVersionTo312