Upgrade to Python 3.12
ProprietaryMigrate 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. UpgradeToPython312mod run . --recipe= org. openrewrite. python. migrate. UpgradeToPython312Install 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.
- Upgrade to Python 3.11
- Replace
datetime.utcnow()withdatetime.now(UTC).replace(tzinfo=None) - Replace
datetime.utcfromtimestamp()withdatetime.fromtimestamp(ts, UTC).replace(tzinfo=None) - Replace deprecated
calendarmonth constants with uppercase - Change import
- Find deprecated
impmodule usage - Find imports of the deprecated
distutils.versionmodule - Find deprecated
distutilsmodule usage - Replace
pkgutil.find_loader()withimportlib.util.find_spec() - Replace
pkgutil.get_loader()withimportlib.util.find_spec() - Find deprecated
Path.link_to()usage - Find modules removed in Python 3.12
- Find deprecated
ssl.match_hostname() - Find deprecated
os.popen()usage - Find deprecated
os.spawn*()usage - Find deprecated
shutil.rmtree(onerror=...)parameter - Replace
sys.last_type/sys.last_value/sys.last_tracebackwithsys.last_exc - Add the
assert_prefix to mock assertions that lack it - Replace
~on aboolwith~int() - Find bitwise inversion
~on abool - Find deprecated
ByteString - org.openrewrite.python.migrate.UpgradePythonVersionTo312