From b368ea773a69eb34fb1d2934afb23ea6466154af Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 3 Jul 2022 07:29:36 -0700 Subject: [PATCH] remove some unneeded calls to _partitions_to_src --- reorder_python_imports.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/reorder_python_imports.py b/reorder_python_imports.py index 7e63bc6..8c5cf07 100644 --- a/reorder_python_imports.py +++ b/reorder_python_imports.py @@ -115,11 +115,7 @@ def partition_source(src: str) -> list[CodePartition]: chunks.append(CodePartition(CodeType.CODE, srctext)) break - chunks = [chunk for chunk in chunks if chunk.src] - - # Make sure we're not removing any code - assert _partitions_to_src(chunks) == src - return chunks + return [chunk for chunk in chunks if chunk.src] def combine_trailing_code_chunks( @@ -380,16 +376,6 @@ def apply_import_sorting( if new_imports: new_imports.pop() - # There's the potential that we moved a bunch of whitespace onto the - # beginning of the rest of the code. To fix this, we're going to combine - # all of that code, and then make sure there are two linebreaks to start - restsrc = _partitions_to_src(rest) - restsrc = restsrc.rstrip() - if restsrc: - rest = [CodePartition(CodeType.CODE, restsrc + '\n')] - else: - rest = [] - return pre_import_code + new_imports + rest