From 7cc1bfa4209a657768b203d91f2349b4311611ee Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 20 Jun 2023 16:49:08 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Parse=20the=20module=20onc?= =?UTF-8?q?e=20instead=20of=20=5Fcodemod=5F=20times?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bump_pydantic/main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bump_pydantic/main.py b/bump_pydantic/main.py index 50f125d..151ad3c 100644 --- a/bump_pydantic/main.py +++ b/bump_pydantic/main.py @@ -105,27 +105,26 @@ def run_codemods( code = fp.read() fp.seek(0) - input_code = str(code) + input_tree = cst.parse_module(code) for codemod in codemods: transformer = codemod(context=context) - input_tree = cst.parse_module(input_code) output_tree = transformer.transform_module(input_tree) + input_tree = output_tree - input_code = output_tree.code - - if code != input_code: + output_code = input_tree.code + if code != output_code: if diff: lines = difflib.unified_diff( code.splitlines(keepends=True), - input_code.splitlines(keepends=True), + output_code.splitlines(keepends=True), fromfile=filename, tofile=filename, ) return list(lines) else: - fp.write(input_code) + fp.write(output_code) fp.truncate() return None