Skip to content

Fix bugs and performance issues in rewrite-python#6851

Merged
jkschneider merged 4 commits intomainfrom
warm-otter
Mar 5, 2026
Merged

Fix bugs and performance issues in rewrite-python#6851
jkschneider merged 4 commits intomainfrom
warm-otter

Conversation

@knutwannheden
Copy link
Contributor

Summary

  • Bug fixes: Fix FileAttributes constructor argument order, InMemoryExecutionContext class-vs-instance attribute bug, != to is not identity checks across tree/support types, deque.pop(0) to popleft() in receive queue, visitor identity-check optimizations in extensions
  • Extract shared utilities: Deduplicate import helpers (get_qualid_name, get_name_string, get_alias_name, pad_right) into import_utils.py and format helpers (common_margin, concatenate_prefix) into format/_helpers.py
  • Buffer RPC stdin reads: Replace byte-at-a-time os.read(fd, 1) with a buffered _StdinBuffer class that reads in 8 KB chunks, reducing syscalls per message from ~25+ to 1-2

Test plan

  • All 1045 existing Python unit tests pass (0 failures, 11 skipped)
  • Import-related tests: test_add_import.py (13 passed), test_remove_import.py, test_change_import.py (18 passed)
  • Format tests: test_auto_format_helpers.py (3 passed)
  • All modified files pass py_compile

- Fix shared class-level mutable dict in InMemoryExecutionContext that
  caused state leakage between instances
- Fix swapped last_access_time/last_modified_time args in
  FileAttributes.from_path
- Fix error message in Cursor.first_enclosing_or_throw using wrong
  variable (T.__name__ instead of type.__name__)
- Use identity check (is not) instead of equality (!=) in all 63
  PaddingHelper.padding properties to avoid O(n) __eq__ comparisons
- Use deque.popleft() instead of list.pop(0) in RpcReceiveQueue for
  O(1) message consumption
- Combine multiple replace() calls into single operations in
  visit_right_padded and parse_python_source
- Remove unused imports and dead code
- Extract duplicated import helpers (get_qualid_name, get_name_string,
  get_alias_name, pad_right) into import_utils.py, replacing copies in
  add_import.py, remove_import.py, and change_import.py
- Extract duplicated format helpers (common_margin, concatenate_prefix)
  into format/_helpers.py, replacing copies in minimum_viable_spacing.py
  and normalize_format.py
- Replace byte-at-a-time os.read(fd, 1) in RPC server with a buffered
  _StdinBuffer that reads in 8 KB chunks, reducing syscalls per message
  from ~25+ to 1-2
@jkschneider jkschneider merged commit f01a14a into main Mar 5, 2026
1 check passed
@jkschneider jkschneider deleted the warm-otter branch March 5, 2026 04:10
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants