From a2b8c44e8f1dfaf356b4979bd57c1075a11e7d26 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 29 Feb 2020 23:31:57 +0100 Subject: [PATCH] Get rid of Python's universal newlines for refactoring --- jedi/api/refactoring/__init__.py | 6 +++--- test/refactor/inline.py | 8 ++++---- test/test_api/test_refactoring.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jedi/api/refactoring/__init__.py b/jedi/api/refactoring/__init__.py index 131e22c0..44052cbb 100644 --- a/jedi/api/refactoring/__init__.py +++ b/jedi/api/refactoring/__init__.py @@ -44,7 +44,7 @@ class ChangedFile(object): 'Cannot apply a refactoring on a Script with path=None' ) - with open(self._from_path, 'w') as f: + with open(self._from_path, 'w', newline='') as f: f.write(self.get_new_code()) def __repr__(self): @@ -77,7 +77,7 @@ class Refactoring(object): to_path=calculate_to_path(path), module_node=next(iter(map_)).get_root_node(), node_to_str_map=map_ - ) for path, map_ in self._file_to_node_changes.items() + ) for path, map_ in sorted(self._file_to_node_changes.items()) } def get_renames(self): @@ -86,7 +86,7 @@ class Refactoring(object): Returns ``Iterable[Tuple[str, str]]``. """ - return sorted(self._renames, key=lambda x: (-len(x), x)) + return sorted(self._renames) def get_diff(self): text = '' diff --git a/test/refactor/inline.py b/test/refactor/inline.py index 5d8b5f5b..a506ec0e 100644 --- a/test/refactor/inline.py +++ b/test/refactor/inline.py @@ -69,6 +69,10 @@ from import_tree import inline_mod #? 22 test(x, inline_mod. inline_var.conjugate) # ++++++++++++++++++++++++++++++++++++++++++++++++++ +--- import_tree/inline_mod.py ++++ import_tree/inline_mod.py +@@ -1,2 +1 @@ +-inline_var = 5 + 3 --- inline.py +++ inline.py @@ -1,4 +1,4 @@ @@ -76,10 +80,6 @@ test(x, inline_mod. inline_var.conjugate) #? 22 -test(x, inline_mod. inline_var.conjugate) +test(x, (5 + 3).conjugate) ---- import_tree/inline_mod.py -+++ import_tree/inline_mod.py -@@ -1,2 +1 @@ --inline_var = 5 + 3 # -------------------------------------------------- class class A: pass #? 5 error diff --git a/test/test_api/test_refactoring.py b/test/test_api/test_refactoring.py index c160b9f3..b43e7834 100644 --- a/test/test_api/test_refactoring.py +++ b/test/test_api/test_refactoring.py @@ -15,7 +15,7 @@ def skip_old_python(skip_pre_python36): @pytest.fixture() def dir_with_content(tmpdir): - with open(os.path.join(tmpdir.strpath, 'modx.py'), 'w') as f: + with open(os.path.join(tmpdir.strpath, 'modx.py'), 'w', newline='') as f: f.write('import modx\nfoo\n') # self reference return tmpdir.strpath