openrewrite-migrate-python 0.17.0.dev20261021162604__tar.gz → 0.17.0.dev20261021163739__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/PKG-INFO +1 -1
  2. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/pyproject.toml +1 -1
  3. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/_literals.py +1 -1
  4. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/boolean_simplification.py +32 -58
  5. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/collection_literals.py +8 -3
  6. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/comparison_simplification.py +16 -5
  7. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/complex_transforms.py +9 -3
  8. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/comprehension_cleanup.py +7 -2
  9. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/dict_cleanup.py +1 -0
  10. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/expression_simplification.py +5 -1
  11. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/none_and_identity.py +20 -9
  12. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/range_cleanup.py +15 -5
  13. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/redundant_code.py +3 -1
  14. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/string_cleanup.py +20 -5
  15. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/use_items.py +5 -1
  16. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/use_list_clear.py +8 -12
  17. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/all_branches_identical.py +26 -2
  18. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/merge_identical_branches.py +17 -15
  19. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/remove_duplicate_conditions.py +11 -14
  20. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/remove_self_assignment.py +41 -28
  21. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/simplify_redundant_logical_expression.py +12 -2
  22. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/__init__.py +4 -1
  23. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_module_imports.py +6 -2
  24. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/ast_deprecations.py +34 -14
  25. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/asyncio_coroutine_to_async.py +20 -3
  26. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/backoff_to_tenacity.py +80 -55
  27. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/calendar_deprecations.py +10 -32
  28. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/datetime_utc.py +7 -4
  29. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/distutils_migrations.py +10 -35
  30. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/html_parser_deprecations.py +15 -1
  31. openrewrite_migrate_python-0.17.0.dev20261021163739/src/openrewrite_migrate_python/migrate/inspect_deprecations.py +84 -0
  32. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pkgutil_deprecations.py +9 -5
  33. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/platform_deprecations.py +6 -1
  34. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pydantic_deprecations.py +30 -8
  35. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pydantic_fields.py +8 -3
  36. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pydantic_model_fields.py +7 -2
  37. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/string_formatting.py +17 -13
  38. openrewrite_migrate_python-0.17.0.dev20261021163739/src/openrewrite_migrate_python/migrate/sys_deprecations.py +153 -0
  39. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/sys_last_deprecations.py +24 -3
  40. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/threading_deprecations.py +29 -9
  41. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/typing_union_to_pipe.py +69 -56
  42. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_langchain1.py +2 -5
  43. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python311.py +4 -2
  44. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python39.py +12 -5
  45. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/xml_deprecations.py +5 -0
  46. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/PKG-INFO +1 -1
  47. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/SOURCES.txt +2 -0
  48. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_asyncio_coroutine_to_async.py +41 -1
  49. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_backoff_to_tenacity.py +30 -0
  50. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_calendar_deprecations.py +4 -40
  51. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_change_import_recipes.py +0 -36
  52. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_datetime_utc.py +22 -0
  53. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_distutils_migrations.py +13 -0
  54. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_html_parser_deprecations.py +34 -0
  55. openrewrite_migrate_python-0.17.0.dev20261021163739/tests/test_inspect_deprecations.py +28 -0
  56. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_langchain_classic_imports.py +13 -0
  57. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pkgutil_deprecations.py +12 -0
  58. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pydantic_deprecations.py +65 -0
  59. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pydantic_fields.py +20 -0
  60. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pydantic_model_fields.py +37 -0
  61. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_string_formatting.py +10 -2
  62. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_sys_deprecations.py +26 -1
  63. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_sys_last_deprecations.py +31 -0
  64. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_threading_extended.py +47 -0
  65. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_typing_union_to_pipe.py +59 -2
  66. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_upgrade_recipes.py +7 -0
  67. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_xml_deprecations.py +13 -0
  68. openrewrite_migrate_python-0.17.0.dev20261021162604/src/openrewrite_migrate_python/migrate/sys_deprecations.py +0 -78
  69. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/setup.cfg +0 -0
  70. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/__init__.py +0 -0
  71. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/__init__.py +0 -0
  72. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/assign_return.py +0 -0
  73. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/attr_access.py +0 -0
  74. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/conditionals.py +0 -0
  75. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/datetime_cleanup.py +0 -0
  76. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/exception_cleanup.py +0 -0
  77. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/logger_warn.py +0 -0
  78. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/loop_cleanup.py +0 -0
  79. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/merge_nested_with.py +0 -0
  80. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/merge_startswith_endswith.py +0 -0
  81. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/naming_conventions.py +0 -0
  82. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/negated_operators.py +0 -0
  83. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/object_inheritance.py +0 -0
  84. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/pandas_cleanup.py +0 -0
  85. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/python_best_practices.py +0 -0
  86. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/remove_trailing_return_none.py +0 -0
  87. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/unreachable_code.py +0 -0
  88. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/cleanup/yoda_conditions.py +0 -0
  89. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/__init__.py +0 -0
  90. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/_reindent.py +0 -0
  91. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/_semantically_equal.py +0 -0
  92. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/_side_effects.py +0 -0
  93. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/_trivia.py +0 -0
  94. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/_truth_value.py +0 -0
  95. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/boolean_checks_not_inverted.py +0 -0
  96. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/code_quality.py +0 -0
  97. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/collapsible_if_statements.py +0 -0
  98. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/find_suspicious_chained_comparison.py +0 -0
  99. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/remove_unconditional_value_overwrite.py +0 -0
  100. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_code_quality_python/codequality/simplify_boolean_literal.py +0 -0
  101. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/__init__.py +0 -0
  102. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_decorators.py +0 -0
  103. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_langchain_tables.py +0 -0
  104. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_markers.py +0 -0
  105. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_method_renames.py +0 -0
  106. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/_slots.py +0 -0
  107. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/aifc_migrations.py +0 -0
  108. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/array_deprecations.py +0 -0
  109. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/asyncio_deprecations.py +0 -0
  110. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/avro_migrations.py +0 -0
  111. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/cgi_migrations.py +0 -0
  112. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/cgi_parse_deprecations.py +0 -0
  113. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/collections_abc_migrations.py +0 -0
  114. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/configparser_deprecations.py +0 -0
  115. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/distutils_deprecations.py +0 -0
  116. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/functools_deprecations.py +0 -0
  117. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/future_imports.py +0 -0
  118. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/gettext_deprecations.py +0 -0
  119. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/imp_migrations.py +0 -0
  120. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/langchain_classic_imports.py +0 -0
  121. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/langchain_community_imports.py +0 -0
  122. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/langchain_provider_imports.py +0 -0
  123. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/locale_deprecations.py +0 -0
  124. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/locale_getdefaultlocale_deprecation.py +0 -0
  125. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/macpath_deprecations.py +0 -0
  126. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/mailcap_migrations.py +0 -0
  127. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/nntplib_migrations.py +0 -0
  128. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/os_deprecations.py +0 -0
  129. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pathlib_deprecations.py +0 -0
  130. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pep594_system_migrations.py +0 -0
  131. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/pipes_migrations.py +0 -0
  132. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/re_deprecations.py +0 -0
  133. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/removed_modules_312.py +0 -0
  134. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/shutil_deprecations.py +0 -0
  135. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/socket_deprecations.py +0 -0
  136. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/ssl_deprecations.py +0 -0
  137. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/tarfile_deprecations.py +0 -0
  138. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/telnetlib_migrations.py +0 -0
  139. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/tempfile_deprecations.py +0 -0
  140. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/threading_is_alive_deprecation.py +0 -0
  141. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/typing_callable.py +0 -0
  142. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/typing_deprecations.py +0 -0
  143. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/unittest_deprecations.py +0 -0
  144. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_langchain02.py +0 -0
  145. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_pandas.py +0 -0
  146. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_pydantic.py +0 -0
  147. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python310.py +0 -0
  148. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python312.py +0 -0
  149. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python313.py +0 -0
  150. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python314.py +0 -0
  151. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python315.py +0 -0
  152. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/upgrade_to_python38.py +0 -0
  153. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/urllib_deprecations.py +0 -0
  154. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/uu_migrations.py +0 -0
  155. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python/migrate/xdrlib_migrations.py +0 -0
  156. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/dependency_links.txt +0 -0
  157. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/entry_points.txt +0 -0
  158. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/requires.txt +0 -0
  159. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/src/openrewrite_migrate_python.egg-info/top_level.txt +0 -0
  160. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_aifc_migrations.py +0 -0
  161. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_array_deprecations.py +0 -0
  162. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_ast_deprecations.py +0 -0
  163. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_asyncio_deprecations.py +0 -0
  164. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_avro_migrations.py +0 -0
  165. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_cgi_parse_deprecations.py +0 -0
  166. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_collections_abc_migrations.py +0 -0
  167. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_configparser_deprecations.py +0 -0
  168. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_distutils_deprecations.py +0 -0
  169. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_functools_deprecations.py +0 -0
  170. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_future_imports.py +0 -0
  171. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_gettext_deprecations.py +0 -0
  172. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_imp_migrations.py +0 -0
  173. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_langchain_community_imports.py +0 -0
  174. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_langchain_provider_imports.py +0 -0
  175. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_locale_deprecations.py +0 -0
  176. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_locale_getdefaultlocale_deprecation.py +0 -0
  177. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_macpath_deprecations.py +0 -0
  178. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_mailcap_migrations.py +0 -0
  179. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_markers.py +0 -0
  180. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_os_deprecations.py +0 -0
  181. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pathlib_deprecations.py +0 -0
  182. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pep594_migrations.py +0 -0
  183. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_pep594_system_migrations.py +0 -0
  184. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_platform_deprecations.py +0 -0
  185. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_re_deprecations.py +0 -0
  186. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_removed_modules_312.py +0 -0
  187. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_shutil_deprecations.py +0 -0
  188. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_socket_deprecations.py +0 -0
  189. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_ssl_deprecations.py +0 -0
  190. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_tarfile_deprecations.py +0 -0
  191. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_tempfile_deprecations.py +0 -0
  192. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_threading_deprecations.py +0 -0
  193. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_threading_is_alive_deprecation.py +0 -0
  194. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_typing_alias_moves.py +0 -0
  195. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_typing_callable.py +0 -0
  196. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_typing_deprecations.py +0 -0
  197. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_unittest_deprecations.py +0 -0
  198. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_upgrade_to_pydantic.py +0 -0
  199. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_urllib_deprecations.py +0 -0
  200. {openrewrite_migrate_python-0.17.0.dev20261021162604 → openrewrite_migrate_python-0.17.0.dev20261021163739}/tests/test_xdrlib_migrations.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openrewrite-migrate-python
3
- Version: 0.17.0.dev20261021162604
3
+ Version: 0.17.0.dev20261021163739
4
4
  Summary: OpenRewrite recipes for migrating Python codebases to newer Python versions.
5
5
  Author-email: "Moderne Inc." <support@moderne.io>
6
6
  License: Moderne Proprietary
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "openrewrite-migrate-python"
7
7
  description = "OpenRewrite recipes for migrating Python codebases to newer Python versions."
8
- version = "0.17.0.dev20261021162604" # Updated dynamically during release
8
+ version = "0.17.0.dev20261021163739" # Updated dynamically during release
9
9
  authors = [{ name = "Moderne Inc.", email = "support@moderne.io" }]
10
10
  license = { text = "Moderne Proprietary" }
11
11
  readme = "README.md"
@@ -19,5 +19,5 @@ def is_string_literal(expr: Any) -> bool:
19
19
 
20
20
 
21
21
  def is_bytes_literal(expr: Literal) -> bool:
22
- """Whether ``expr`` is a ``b``-prefixed literal, which the parser types as ``str``."""
22
+ """Whether ``expr`` is a ``b``-prefixed literal, which the parser does not type as ``bytes``."""
23
23
  return "b" in _prefix(expr.value_source or "").lower()
@@ -32,10 +32,10 @@ from rewrite.python.template import pattern, template, capture
32
32
  from rewrite.python.template.pattern import MatchResult
33
33
  from rewrite.java.tree import (
34
34
  Binary as JBinary, Block, ControlParentheses, Empty, Expression, If as JIf, J,
35
- Literal, MethodInvocation, Parentheses, Return, Ternary as JTernary, Unary,
35
+ Literal, MethodInvocation, Return, Ternary as JTernary, Unary,
36
36
  WhileLoop as JWhileLoop,
37
37
  )
38
- from rewrite.java.support_types import JavaType, JLeftPadded, JRightPadded, Space
38
+ from rewrite.java.support_types import JavaType, Space
39
39
  from rewrite.python.tree import (
40
40
  Binary as PyBinary, CollectionLiteral, DictLiteral, KeyValue, Star,
41
41
  )
@@ -75,8 +75,8 @@ _len_eq_0_pattern = pattern("len({lc_x}) == 0", lc_x=_lc_x)
75
75
  _len_gte_1_pattern = pattern("len({lc_x}) >= 1", lc_x=_lc_x)
76
76
  _LEN_PATTERN = "builtins len(..)"
77
77
  _LEN = MethodMatcher.create(_LEN_PATTERN)
78
- # Classes whose truth value is defined by their length. ty types `bytes` as `str`.
79
- _SIZED_CLASSES = ("list", "tuple", "dict", "set", "frozenset", "bytearray")
78
+ # Classes whose truth value is defined by their length.
79
+ _SIZED_CLASSES = ("list", "tuple", "dict", "set", "frozenset", "bytes", "bytearray")
80
80
  _lc_x_template = template("{lc_x}", lc_x=_lc_x)
81
81
  _lc_not_x_template = template("not {lc_x}", lc_x=_lc_x)
82
82
 
@@ -153,6 +153,7 @@ def _is_not(expr: Expression) -> bool:
153
153
 
154
154
  _as_bool_cond = capture('cond')
155
155
  _bool_template = template("bool({cond})", cond=_as_bool_cond)
156
+ _not_cond_template = template("not {cond}", cond=_as_bool_cond)
156
157
 
157
158
 
158
159
  def _as_bool(cond: Expression, cursor: Cursor) -> Expression | None:
@@ -209,15 +210,14 @@ class BooleanIfExpIdentity(Recipe):
209
210
  return ["python", "cleanup", "ruff", "SIM210", "SIM211", "RUF034"]
210
211
 
211
212
  def editor(self) -> TreeVisitor[Any, ExecutionContext]:
212
- _cond = capture('cond')
213
- _not_cond_template = template("not {cond}", cond=_cond)
214
-
215
213
  class Visitor(PythonVisitor[ExecutionContext]):
216
214
  def visit_ternary(
217
215
  self, ternary: JTernary, p: ExecutionContext
218
216
  ) -> J:
219
217
  visited = super().visit_ternary(ternary, p)
220
- if not isinstance(visited, JTernary):
218
+ if not isinstance(visited, JTernary) or has_comments(
219
+ visited.replace(_prefix=Space.EMPTY)
220
+ ):
221
221
  return visited
222
222
  ternary = visited
223
223
 
@@ -305,7 +305,9 @@ class RemoveRedundantBoolean(Recipe):
305
305
  binary = visited
306
306
 
307
307
  # Guard: at least one side must be an actual True/False literal (not 1/0)
308
- if not self._has_any_bool_literal(binary):
308
+ if not self._has_any_bool_literal(binary) or has_comments(
309
+ binary.replace(_prefix=Space.EMPTY)
310
+ ):
309
311
  return binary
310
312
 
311
313
  # `x and True` yields True, not x, for a truthy x, so a literal on the
@@ -429,7 +431,9 @@ class DeMorgan(Recipe):
429
431
  self, unary: Unary, p: ExecutionContext
430
432
  ) -> J:
431
433
  visited = super().visit_unary(unary, p)
432
- if not isinstance(visited, Unary):
434
+ if not isinstance(visited, Unary) or has_comments(
435
+ visited.replace(_prefix=Space.EMPTY)
436
+ ):
433
437
  return visited
434
438
  unary = visited
435
439
  cursor = Cursor(self.cursor.parent, unary)
@@ -526,7 +530,7 @@ class SimplifyLenComparison(Recipe):
526
530
  "Rewrite `len(seq) > 0`, `len(seq) != 0` and `len(seq) >= 1` to `seq` "
527
531
  "and `len(seq) == 0` to `not seq`. Only fires where the comparison "
528
532
  "is read as a truth value and the type of `seq` resolves to a builtin "
529
- "string, list, tuple, dict, set, frozenset or bytearray, whose truth "
533
+ "string, list, tuple, dict, set, frozenset, bytes or bytearray, whose truth "
530
534
  "value is its length."
531
535
  )
532
536
 
@@ -550,6 +554,7 @@ class SimplifyLenComparison(Recipe):
550
554
  or not _is_sized_builtin(call.arguments[0].type)
551
555
  or not is_read_as_truth_value(self.cursor)
552
556
  or not _LEN.matches(call, cursor=Cursor(self.cursor, call))
557
+ or has_comments(binary.replace(_prefix=Space.EMPTY))
553
558
  ):
554
559
  return binary
555
560
 
@@ -755,9 +760,8 @@ class SimplifyBooleanReturn(Recipe):
755
760
  "`return cond` and the inverse with `return not cond`, including the "
756
761
  "fallthrough variant without an explicit `else`. A condition other than "
757
762
  "a comparison, a `not`, or an `and`/`or` of those is returned as "
758
- "`bool(cond)`. The "
759
- "rewrite is declined where `bool` is not the builtin or the removed "
760
- "statements hold comments."
763
+ "`bool(cond)`. The rewrite is declined on an `elif`, where `bool` is "
764
+ "not the builtin, or where the removed statements hold comments."
761
765
  )
762
766
 
763
767
  @property
@@ -788,54 +792,22 @@ class SimplifyBooleanReturn(Recipe):
788
792
  _expression=expression.replace(_prefix=Space.SINGLE_SPACE),
789
793
  )
790
794
 
791
- def _make_not(self, expression) -> Unary:
792
- """Wrap expression in `not`, adding parentheses for compound expressions.
793
-
794
- Without parentheses, `not A and B` is parsed as `(not A) and B`
795
- due to Python's operator precedence. When the intent is
796
- `not (A and B)`, we must wrap in `J.Parentheses`.
797
- """
798
- inner = expression
799
- # Wrap and/or compounds in parens to preserve semantics
800
- if isinstance(expression, JBinary) and expression.operator in (
801
- JBinary.Type.And, JBinary.Type.Or,
802
- ):
803
- inner = Parentheses(
804
- _id=uuid.uuid4(),
805
- _prefix=Space.SINGLE_SPACE,
806
- _markers=Markers.EMPTY,
807
- _tree=JRightPadded(
808
- _element=expression.replace(_prefix=Space.EMPTY),
809
- _after=Space.EMPTY,
810
- _markers=Markers.EMPTY,
811
- ),
812
- )
813
- else:
814
- inner = expression.replace(_prefix=Space.SINGLE_SPACE)
815
- return Unary(
816
- _id=uuid.uuid4(),
817
- _prefix=Space.SINGLE_SPACE,
818
- _markers=Markers.EMPTY,
819
- _operator=JLeftPadded(
820
- _before=Space.EMPTY,
821
- _element=Unary.Type.Not,
822
- _markers=Markers.EMPTY,
823
- ),
824
- _expression=inner,
825
- _type=JavaType.Primitive.Boolean,
826
- )
827
-
828
795
  def _simplify_return(
829
796
  self, if_: JIf, parent: Cursor, then_is_true: bool, else_is_true: bool
830
797
  ) -> Return | None:
831
798
  """Build Return for the simplified boolean pattern."""
832
799
  cond = self._unwrap_condition(if_.if_condition)
833
- if then_is_true and not else_is_true:
834
- as_bool = _as_bool(cond, Cursor(Cursor(parent, if_), cond))
835
- return None if as_bool is None else self._make_return(if_.prefix, as_bool)
836
- elif not then_is_true and else_is_true:
837
- return self._make_return(if_.prefix, self._make_not(cond))
838
- return None
800
+ cursor = Cursor(Cursor(parent, if_), cond)
801
+ if then_is_true == else_is_true:
802
+ return None
803
+ if then_is_true:
804
+ result = _as_bool(cond, cursor)
805
+ elif _is_not(cond):
806
+ result = _as_bool(cond.expression, Cursor(cursor, cond.expression))
807
+ else:
808
+ negated = _not_cond_template.apply(cursor, values=MatchResult({'cond': cond}))
809
+ result = negated if isinstance(negated, Expression) else None
810
+ return None if result is None else self._make_return(if_.prefix, result)
839
811
 
840
812
  def visit_if(
841
813
  self, if_: JIf, p: ExecutionContext
@@ -845,9 +817,11 @@ class SimplifyBooleanReturn(Recipe):
845
817
  return visited
846
818
  if_stmt = visited
847
819
 
848
- # Only handle explicit else pattern here
820
+ # Only handle explicit else pattern here. An `elif` is the body of
821
+ # its enclosing `else`, where a `return` cannot take its place.
849
822
  if (
850
823
  if_stmt.else_part is None
824
+ or isinstance(self.cursor.parent_tree_cursor().value, JIf.Else)
851
825
  or has_comments(if_stmt.then_part)
852
826
  or has_comments(if_stmt.else_part)
853
827
  ):
@@ -373,10 +373,15 @@ class UnwrapIterableConstruction(Recipe):
373
373
  _type=_literal_type(method, target_kind),
374
374
  )
375
375
  # Single-element tuple needs trailing comma: (x,)
376
- if target_kind == CollectionLiteral.Kind.TUPLE and len(arg.elements) == 1:
376
+ padded = list(result.padding.elements.padding.elements)
377
+ last = padded[-1]
378
+ if (
379
+ target_kind == CollectionLiteral.Kind.TUPLE
380
+ and len(padded) == 1
381
+ and not isinstance(last.element, Empty)
382
+ and last.markers.find_first(TrailingComma) is None
383
+ ):
377
384
  container = result.padding.elements
378
- padded = list(container.padding.elements)
379
- last = padded[-1]
380
385
  tc = TrailingComma(random_id(), last.after)
381
386
  new_markers = last.markers.replace(markers=last.markers.markers + [tc])
382
387
  padded[-1] = last.replace(_markers=new_markers, _after=Space.EMPTY)
@@ -60,7 +60,11 @@ def _is_substring_search(binary: JBinary, match: MatchResult, cursor: Cursor) ->
60
60
  and any(m.matches(call, cursor=Cursor(cursor, call)) for m in _FIND)
61
61
  and isinstance(receiver, Expression)
62
62
  and isinstance(sub, Expression)
63
- and (is_string(receiver.type) or is_of_class_type(receiver.type, "bytearray"))
63
+ and (
64
+ is_string(receiver.type)
65
+ or is_of_class_type(receiver.type, "bytes")
66
+ or is_of_class_type(receiver.type, "bytearray")
67
+ )
64
68
  and is_side_effect_free(receiver)
65
69
  and is_side_effect_free(sub)
66
70
  )
@@ -102,7 +106,8 @@ class SimplifySubstringSearch(Recipe):
102
106
  "`text.find(sub) != -1` becomes `sub in text`. "
103
107
  "It only fires where the receiver's type resolves to `str`, "
104
108
  "`bytes` or `bytearray` (not a subclass), and declines operands with "
105
- "side effects, because `in` evaluates them in the opposite order."
109
+ "side effects, because `in` evaluates them in the opposite order, "
110
+ "and a comparison holding comments."
106
111
  )
107
112
 
108
113
  @property
@@ -120,7 +125,11 @@ class SimplifySubstringSearch(Recipe):
120
125
  (_find_neq_neg1_pattern, _in_template),
121
126
  ):
122
127
  match = pat.match(visited, self.cursor)
123
- if match and _is_substring_search(visited, match, self.cursor):
128
+ if (
129
+ match
130
+ and _is_substring_search(visited, match, self.cursor)
131
+ and not has_comments(visited.replace(prefix=Space.EMPTY))
132
+ ):
124
133
  result = tmpl.apply(self.cursor, values=match)
125
134
  return result if result is not None else visited
126
135
  return visited
@@ -203,9 +212,11 @@ class MergeComparisons(Recipe):
203
212
  collection = left.right
204
213
  container = collection.padding.elements
205
214
  old_padded = list(container.padding.elements)
206
- # Append the new value with leading space
215
+ # The new last element takes over the trailing comma and the space before `]`.
216
+ last = old_padded[-1]
207
217
  new_elem = right.right.replace(_prefix=Space.SINGLE_SPACE)
208
- old_padded.append(JRightPadded(new_elem, Space.EMPTY, Markers.EMPTY))
218
+ old_padded[-1] = last.replace(after=Space.EMPTY, markers=Markers.EMPTY)
219
+ old_padded.append(JRightPadded(new_elem, last.after, last.markers))
209
220
  new_container = container.padding.replace(elements=old_padded)
210
221
  new_collection = collection.padding.replace(_elements=new_container)
211
222
  return left.replace(_right=new_collection, _prefix=visited.prefix)
@@ -31,6 +31,7 @@ from rewrite.java.tree import (
31
31
  from rewrite.java.support_types import JContainer, JLeftPadded, JRightPadded, Space
32
32
  from rewrite.utils import random_id
33
33
  from openrewrite_code_quality_python.cleanup.assign_return import count_mentions
34
+ from openrewrite_code_quality_python.codequality._trivia import has_comments
34
35
 
35
36
  # Define category path: Python > Cleanup
36
37
  _Cleanup = [*Python, CategoryDescriptor(display_name="Cleanup")]
@@ -87,7 +88,7 @@ class TernaryToIfExpression(Recipe):
87
88
  "Rewrite the legacy `cond and val or fallback` idiom as "
88
89
  "`val if cond else fallback`. It only fires where `val` is a literal "
89
90
  "that is always truthy, such as a non-empty string, since a falsy `val` "
90
- "makes the idiom yield `fallback`."
91
+ "makes the idiom yield `fallback`. An idiom holding comments is left alone."
91
92
  )
92
93
 
93
94
  @property
@@ -101,7 +102,11 @@ class TernaryToIfExpression(Recipe):
101
102
  if not isinstance(visited, JBinary):
102
103
  return visited
103
104
  match = _ternary_pattern.match(visited, self.cursor)
104
- if match and _is_always_truthy(match['x']):
105
+ if (
106
+ match
107
+ and _is_always_truthy(match['x'])
108
+ and not has_comments(visited.replace(prefix=Space.EMPTY))
109
+ ):
105
110
  result = _ternary_template.apply(self.cursor, values=match)
106
111
  assert result is not None
107
112
  return result
@@ -268,7 +273,8 @@ class SwapVariable(Recipe):
268
273
  ),
269
274
  _type=None,
270
275
  )
271
- padded_swap = stmts[idx].replace(_element=swap_assign)
276
+ # The last statement's padding records the `;` that follows the swap, if any.
277
+ padded_swap = stmts[idx + 2].replace(_element=swap_assign)
272
278
 
273
279
  # Replace the 3 statements with 1
274
280
  new_stmts = list(stmts)
@@ -37,6 +37,7 @@ from rewrite.python.template import template, capture
37
37
  from rewrite.python.template.pattern import MatchResult
38
38
  from rewrite.java.markers import OmitParentheses, TrailingComma
39
39
  from rewrite.java.support_types import JavaType, Space
40
+ from openrewrite_code_quality_python.codequality._trivia import has_comments
40
41
  from rewrite.utils import random_id
41
42
  from rewrite.java.tree import (
42
43
  Binary as JBinary, Identifier, J, JContainer, Literal,
@@ -207,7 +208,8 @@ class CollectionBuiltinToComprehension(Recipe):
207
208
  return method
208
209
 
209
210
  gen = _get_single_generator(method)
210
- if gen is None or _is_async(gen):
211
+ if (gen is None or _is_async(gen)
212
+ or has_comments(method.replace(_prefix=Space.EMPTY))):
211
213
  return method
212
214
 
213
215
  # Transform generator expression into the corresponding comprehension
@@ -269,7 +271,7 @@ class SimplifyGenerator(Recipe):
269
271
  return method
270
272
 
271
273
  gen = _get_single_generator(method)
272
- if gen is None:
274
+ if gen is None or has_comments(method.replace(_prefix=Space.EMPTY)):
273
275
  return method
274
276
 
275
277
  # Must have exactly one clause with no conditions
@@ -519,6 +521,9 @@ class IdentityComprehension(Recipe):
519
521
  if kind not in (ComprehensionExpression.Kind.LIST,
520
522
  ComprehensionExpression.Kind.SET):
521
523
  return comp
524
+ # The visitor does not visit a comprehension's suffix, so has_comments misses it.
525
+ if has_comments(comp.replace(_prefix=Space.EMPTY)) or comp.suffix.comments:
526
+ return comp
522
527
 
523
528
  # Must have exactly one clause with no conditions
524
529
  if len(comp.clauses) != 1:
@@ -171,6 +171,7 @@ class RemoveDictKeys(Recipe):
171
171
  not match
172
172
  or not _is_dict(visited.select)
173
173
  or not _is_iterable_or_membership_operand(self.cursor)
174
+ or has_comments(visited.replace(_prefix=Space.EMPTY))
174
175
  ):
175
176
  return visited
176
177
  return _keys_template.apply(self.cursor, values=match) or visited
@@ -276,7 +276,11 @@ class RemoveRedundantSliceIndex(Recipe):
276
276
  return visited
277
277
  array_access = visited
278
278
  idx = array_access.dimension.index
279
- if not isinstance(idx, Slice) or idx.step is not None:
279
+ if (
280
+ not isinstance(idx, Slice)
281
+ or idx.step is not None
282
+ or has_comments(array_access.replace(prefix=Space.EMPTY))
283
+ ):
280
284
  return array_access
281
285
  # start must be literal 0
282
286
  if not isinstance(idx.start, Literal):
@@ -21,7 +21,8 @@ from rewrite.python.template import pattern, template, capture
21
21
  from rewrite.python.type_utils import is_of_class_type
22
22
  from openrewrite_code_quality_python.codequality._semantically_equal import SemanticallyEqual
23
23
  from openrewrite_code_quality_python.codequality._side_effects import is_side_effect_free
24
- from rewrite.java.support_types import JavaType
24
+ from openrewrite_code_quality_python.codequality._trivia import has_comments
25
+ from rewrite.java.support_types import JavaType, Space
25
26
  from rewrite.java.tree import Binary as JBinary, Expression, J, Literal
26
27
 
27
28
  # Define category path: Python > Cleanup
@@ -47,6 +48,11 @@ _zero_template = template("0")
47
48
  _base = capture('base')
48
49
  _power_template = template("{base} ** 2", base=_base)
49
50
 
51
+ def _holds_comments(binary: JBinary) -> bool:
52
+ """Whether replacing ``binary`` would drop a comment. Its prefix carries over."""
53
+ return has_comments(binary.replace(prefix=Space.EMPTY))
54
+
55
+
50
56
  # BinOpIdentity: operators that collapse to zero (self-cancelling)
51
57
  _ZERO_OPS = frozenset({JBinary.Type.BitXor, JBinary.Type.Subtraction})
52
58
 
@@ -119,7 +125,7 @@ class NoneCompare(Recipe):
119
125
  "Switch `== None` to `is None` and `!= None` to `is not None`, following PEP 8 "
120
126
  "singleton comparison guidance. Only fires where the operand's type resolves to "
121
127
  "a builtin. Other operands are left alone, since their `__eq__` may give "
122
- "`== None` another meaning."
128
+ "`== None` another meaning. A comparison holding comments is left alone."
123
129
  )
124
130
 
125
131
  @property
@@ -130,7 +136,11 @@ class NoneCompare(Recipe):
130
136
  class Visitor(PythonVisitor[ExecutionContext]):
131
137
  def visit_binary(self, binary: JBinary, p: ExecutionContext) -> J:
132
138
  b = super().visit_binary(binary, p)
133
- if not isinstance(b, JBinary) or not _has_builtin_eq(b.left.type):
139
+ if (
140
+ not isinstance(b, JBinary)
141
+ or not _has_builtin_eq(b.left.type)
142
+ or _holds_comments(b)
143
+ ):
134
144
  return b
135
145
  match = _eq_none_pattern.match(b, self.cursor)
136
146
  if match:
@@ -176,7 +186,7 @@ class EqualityIdentity(Recipe):
176
186
  return (
177
187
  "When both sides of `==` or `!=` are the same literal, replace the "
178
188
  "expression with `True` or `False` respectively. A comparison of two "
179
- "names, even the same name, is left alone."
189
+ "names, even the same name, or one holding comments is left alone."
180
190
  )
181
191
 
182
192
  @property
@@ -197,7 +207,7 @@ class EqualityIdentity(Recipe):
197
207
  # Both sides must be literals
198
208
  if not isinstance(left, Literal) or not isinstance(right, Literal):
199
209
  return b
200
- if not SemanticallyEqual.are_equal(left, right):
210
+ if not SemanticallyEqual.are_equal(left, right) or _holds_comments(b):
201
211
  return b
202
212
  literal = _true_template if op == JBinary.Type.Equal else _false_template
203
213
  return literal.apply(self.cursor, values={}) or b
@@ -241,7 +251,7 @@ class BinOpIdentity(Recipe):
241
251
  "When both operands of `^` or `-` are the same expression, "
242
252
  "reduce to `0` (the self-cancelling identity). Only fires where the operand's "
243
253
  "type resolves to `int` and it has no side effects, since floats, sets and bools "
244
- "give other results."
254
+ "give other results. An operation holding comments is left alone."
245
255
  )
246
256
 
247
257
  @property
@@ -256,7 +266,7 @@ class BinOpIdentity(Recipe):
256
266
  return b
257
267
  if not _is_pure_int(b.left):
258
268
  return b
259
- if not SemanticallyEqual.are_equal(b.left, b.right):
269
+ if not SemanticallyEqual.are_equal(b.left, b.right) or _holds_comments(b):
260
270
  return b
261
271
  return _zero_template.apply(self.cursor, values={}) or b
262
272
 
@@ -296,7 +306,8 @@ class SquareIdentity(Recipe):
296
306
  "When an expression is multiplied by itself, rewrite it using the "
297
307
  "exponentiation operator (`** 2`) for clarity. Only fires where the operand's "
298
308
  "type resolves to `int` and it has no side effects, since a large float "
299
- "overflows under `**`. A literal times itself, such as `60 * 60`, is left alone."
309
+ "overflows under `**`. A literal times itself, such as `60 * 60`, "
310
+ "or a product holding comments is left alone."
300
311
  )
301
312
 
302
313
  @property
@@ -316,7 +327,7 @@ class SquareIdentity(Recipe):
316
327
  # "seconds per minute × minutes per hour".
317
328
  if isinstance(b.left, Literal):
318
329
  return b
319
- if not SemanticallyEqual.are_equal(b.left, b.right):
330
+ if not SemanticallyEqual.are_equal(b.left, b.right) or _holds_comments(b):
320
331
  return b
321
332
  return _power_template.apply(self.cursor, values={"base": b.left}) or b
322
333
 
@@ -7,14 +7,15 @@ Recipes that strip unnecessary arguments from ``range()`` calls.
7
7
 
8
8
  from typing import Any, List
9
9
 
10
- from rewrite import ExecutionContext, Preconditions, Recipe, TreeVisitor
10
+ from rewrite import Cursor, ExecutionContext, Preconditions, Recipe, TreeVisitor
11
11
  from rewrite.category import CategoryDescriptor
12
12
  from rewrite.decorators import categorize
13
13
  from rewrite.marketplace import Python
14
14
  from rewrite.python.preconditions import uses_method
15
15
  from rewrite.python.visitor import PythonVisitor
16
- from rewrite.python.template import pattern, template, capture
17
- from rewrite.python.tree import Star
16
+ from rewrite.python.template import Template, pattern, template, capture
17
+ from rewrite.python.template.pattern import MatchResult
18
+ from rewrite.python.tree import ExpressionStatement, Star
18
19
  from rewrite.java.tree import J, MethodInvocation
19
20
 
20
21
  _Cleanup = [*Python, CategoryDescriptor(display_name="Cleanup")]
@@ -26,6 +27,15 @@ def _has_unpacked_argument(method: MethodInvocation) -> bool:
26
27
  return any(isinstance(arg, Star) for arg in method.arguments)
27
28
 
28
29
 
30
+ def _apply(tmpl: Template, cursor: Cursor, match: MatchResult, method: MethodInvocation) -> J:
31
+ # `apply` returns the call wrapped in an `ExpressionStatement`, since a call is also a
32
+ # statement. A parse leaves a call bare in every slot.
33
+ result = tmpl.apply(cursor, values=match)
34
+ if isinstance(result, ExpressionStatement):
35
+ result = result.expression
36
+ return result or method
37
+
38
+
29
39
  # Pattern/template for range(0, x) -> range(x)
30
40
  _x = capture('x')
31
41
  _range_zero_pattern = pattern("range(0, {x})", x=_x)
@@ -84,7 +94,7 @@ class RemoveZeroFromRange(Recipe):
84
94
  return visited
85
95
  match = _range_zero_pattern.match(visited, self.cursor)
86
96
  if match:
87
- return _range_zero_template.apply(self.cursor, values=match) or visited
97
+ return _apply(_range_zero_template, self.cursor, match, visited)
88
98
  return visited
89
99
 
90
100
  return Preconditions.check(uses_method(_RANGE), Visitor())
@@ -136,7 +146,7 @@ class RemoveUnitStepFromRange(Recipe):
136
146
  return visited
137
147
  match = _range_step_pattern.match(visited, self.cursor)
138
148
  if match:
139
- return _range_step_template.apply(self.cursor, values=match) or visited
149
+ return _apply(_range_step_template, self.cursor, match, visited)
140
150
  return visited
141
151
 
142
152
  return Preconditions.check(uses_method(_RANGE), Visitor())
@@ -23,6 +23,7 @@ from rewrite.java.tree import (
23
23
  ForEachLoop,
24
24
  J,
25
25
  MethodInvocation,
26
+ Space,
26
27
  WhileLoop,
27
28
  )
28
29
  from openrewrite_code_quality_python.codequality._semantically_equal import SemanticallyEqual
@@ -138,7 +139,7 @@ class RemoveRedundantPathExists(Recipe):
138
139
  "or `is_file()` on the same path, which inherently return `False` for "
139
140
  "missing paths. Only fires where the receiver's type resolves to "
140
141
  "`pathlib.Path`, and leaves a receiver whose evaluation may have side "
141
- "effects, such as a call, alone."
142
+ "effects, such as a call, alone, as well as a check holding comments."
142
143
  )
143
144
 
144
145
  @property
@@ -173,6 +174,7 @@ class RemoveRedundantPathExists(Recipe):
173
174
  or right.select is None
174
175
  or not is_side_effect_free(left.select)
175
176
  or not SemanticallyEqual.are_equal(left.select, right.select)
177
+ or has_comments(visited.replace(prefix=Space.EMPTY))
176
178
  ):
177
179
  return visited
178
180
  return kept.replace(_prefix=visited.prefix)
@@ -81,6 +81,16 @@ _STR_FORMATTED = (
81
81
  )
82
82
 
83
83
 
84
+ def _is_str_formatted(type_: JavaType | None) -> bool:
85
+ """Whether a value of ``type_`` formats as ``str()`` does.
86
+
87
+ A ``float`` annotation reads as ``int | float``, since it accepts an ``int``.
88
+ """
89
+ if isinstance(type_, JavaType.Union):
90
+ return all(bound in _STR_FORMATTED for bound in type_.bounds)
91
+ return type_ in _STR_FORMATTED
92
+
93
+
84
94
  def _is_positional(arg: Any) -> bool:
85
95
  return not isinstance(arg, (Star, NamedArgument, Empty))
86
96
 
@@ -203,7 +213,9 @@ class RemoveStrFromPrint(Recipe):
203
213
  return visited
204
214
  method = visited
205
215
  match = _str_print_pattern.match(method, self.cursor)
206
- if not match or not _PRINT.matches(method, cursor=self.cursor):
216
+ if (not match
217
+ or not _PRINT.matches(method, cursor=self.cursor)
218
+ or has_comments(method.replace(_prefix=Space.EMPTY))):
207
219
  return method
208
220
  inner = method.arguments[0]
209
221
  if (not isinstance(inner, MethodInvocation)
@@ -266,7 +278,8 @@ class RemoveNoneFromDefaultGet(Recipe):
266
278
  match = _get_none_pattern.match(method, self.cursor)
267
279
  if (not match
268
280
  or not _DICT_GET.matches(method, cursor=self.cursor)
269
- or not _is_positional(method.arguments[0])):
281
+ or not _is_positional(method.arguments[0])
282
+ or has_comments(method.replace(_prefix=Space.EMPTY))):
270
283
  return method
271
284
  return _get_none_template.apply(self.cursor, values=match) or method
272
285
 
@@ -437,7 +450,7 @@ class RemoveStrFromFstring(Recipe):
437
450
  args = list(expr.arguments)
438
451
  if len(args) != 1 or not _is_positional(args[0]):
439
452
  return value
440
- if args[0].type not in _STR_FORMATTED:
453
+ if not _is_str_formatted(args[0].type):
441
454
  return value
442
455
 
443
456
  # Skip when the placeholder has a !r or !a conversion.
@@ -504,7 +517,8 @@ class StrPrefixSuffix(Recipe):
504
517
  return visited
505
518
  binary = visited
506
519
 
507
- if binary.operator != Binary.Type.Equal:
520
+ if (binary.operator != Binary.Type.Equal
521
+ or has_comments(binary.replace(_prefix=Space.EMPTY))):
508
522
  return binary
509
523
 
510
524
  left = binary.left
@@ -603,7 +617,8 @@ class UseGetitemForReMatchGroups(Recipe):
603
617
  if not isinstance(visited, MethodInvocation):
604
618
  return visited
605
619
  method = visited
606
- if not _MATCH_GROUP.matches(method, cursor=self.cursor):
620
+ if (not _MATCH_GROUP.matches(method, cursor=self.cursor)
621
+ or has_comments(method.replace(_prefix=Space.EMPTY))):
607
622
  return method
608
623
  args = list(method.arguments)
609
624
  if len(args) != 1 or not _is_positional(args[0]):
@@ -31,10 +31,12 @@ from rewrite.java.tree import (
31
31
  ForEachLoop,
32
32
  J,
33
33
  MethodInvocation,
34
+ Space,
34
35
  )
35
36
 
36
37
  from openrewrite_code_quality_python.codequality._semantically_equal import SemanticallyEqual
37
38
  from openrewrite_code_quality_python.codequality._side_effects import is_side_effect_free
39
+ from openrewrite_code_quality_python.codequality._trivia import has_comments
38
40
 
39
41
  _Cleanup = [*Python, CategoryDescriptor(display_name="Cleanup")]
40
42
 
@@ -100,7 +102,8 @@ class UseItemsForKeyValueIteration(Recipe):
100
102
  "When both `.keys()` and `.values()` are zipped together, "
101
103
  "replace with `.items()` which yields key-value pairs directly. "
102
104
  "Only a `zip` that a for-loop or comprehension iterates directly is replaced, "
103
- "and only where the receiver is a name or attribute read whose type resolves to `dict`."
105
+ "and only where the receiver is a name or attribute read whose type resolves to `dict`. "
106
+ "A `zip` holding comments is left alone."
104
107
  )
105
108
 
106
109
  @property
@@ -130,6 +133,7 @@ class UseItemsForKeyValueIteration(Recipe):
130
133
  or not is_side_effect_free(receiver)
131
134
  or not is_of_class_type(receiver.type, "dict")
132
135
  or not _is_iterated_directly(self.cursor)
136
+ or has_comments(method.replace(prefix=Space.EMPTY))
133
137
  ):
134
138
  return method
135
139