Upgrade to Python 3.9
ProprietaryMigrate deprecated APIs for Python 3.9 compatibility. This includes PEP 585 built-in generics, removed base64 and array methods, and removed XML Element methods, and adopts the dict union operator and str.removeprefix()/removesuffix(). fractions.gcd() becomes math.gcd(), which takes only integers and never returns a negative. Calls to the removed sys.setcheckinterval()/getcheckinterval() are marked, since their replacements measure seconds rather than bytecode instructions.
org. openrewrite. python. migrate. UpgradeToPython39mod run . --recipe= org. openrewrite. python. migrate. UpgradeToPython39Install 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.8
- Change import
- Change import
- Replace
typing.Listwithlist - Replace
typing.Dictwithdict - Replace
typing.Setwithset - Replace
typing.FrozenSetwithfrozenset - Replace
typing.Tuplewithtuple - Replace
typing.Typewithtype - Replace
typing.Callablewithcollections.abc.Callable - Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Change import
- Replace
array.tostring()witharray.tobytes() - Replace
array.fromstring()witharray.frombytes() - Replace
Element.getiterator()withElement.iter() - Replace
Element.getchildren()withlist(element) - Replace
xml.etree.cElementTreewithxml.etree.ElementTree - Change import
- Find removed
sys.setcheckinterval()/sys.getcheckinterval() - Replace
Thread.isAlive()withThread.is_alive() - Replace
HTMLParser.unescape()withhtml.unescape() - Use the
|dict union instead of**unpacking - Replace string slicing with
removeprefix/removesuffix - org.openrewrite.python.migrate.UpgradePythonVersionTo39