Upgrade to Python 3.9

Proprietary

Migrate 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.UpgradeToPython39
mod run . --recipe=org.openrewrite.python.migrate.UpgradeToPython39

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.8
  2. Change import
  3. Change import
  4. Replace typing.List with list
  5. Replace typing.Dict with dict
  6. Replace typing.Set with set
  7. Replace typing.FrozenSet with frozenset
  8. Replace typing.Tuple with tuple
  9. Replace typing.Type with type
  10. Replace typing.Callable with collections.abc.Callable
  11. Change import
  12. Change import
  13. Change import
  14. Change import
  15. Change import
  16. Change import
  17. Change import
  18. Change import
  19. Change import
  20. Change import
  21. Change import
  22. Change import
  23. Change import
  24. Change import
  25. Change import
  26. Change import
  27. Change import
  28. Change import
  29. Change import
  30. Change import
  31. Change import
  32. Change import
  33. Change import
  34. Change import
  35. Change import
  36. Change import
  37. Change import
  38. Change import
  39. Change import
  40. Change import
  41. Change import
  42. Change import
  43. Change import
  44. Replace array.tostring() with array.tobytes()
  45. Replace array.fromstring() with array.frombytes()
  46. Replace Element.getiterator() with Element.iter()
  47. Replace Element.getchildren() with list(element)
  48. Replace xml.etree.cElementTree with xml.etree.ElementTree
  49. Change import
  50. Find removed sys.setcheckinterval() / sys.getcheckinterval()
  51. Replace Thread.isAlive() with Thread.is_alive()
  52. Replace HTMLParser.unescape() with html.unescape()
  53. Use the | dict union instead of ** unpacking
  54. Replace string slicing with removeprefix/removesuffix
  55. org.openrewrite.python.migrate.UpgradePythonVersionTo39