Fix bugs and performance issues in rewrite-python#6851
Merged
jkschneider merged 4 commits intomainfrom Mar 5, 2026
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FileAttributesconstructor argument order,InMemoryExecutionContextclass-vs-instance attribute bug,!=tois notidentity checks across tree/support types,deque.pop(0)topopleft()in receive queue, visitor identity-check optimizations in extensionsget_qualid_name,get_name_string,get_alias_name,pad_right) intoimport_utils.pyand format helpers (common_margin,concatenate_prefix) intoformat/_helpers.pyos.read(fd, 1)with a buffered_StdinBufferclass that reads in 8 KB chunks, reducing syscalls per message from ~25+ to 1-2Test plan
test_add_import.py(13 passed),test_remove_import.py,test_change_import.py(18 passed)test_auto_format_helpers.py(3 passed)py_compile