Skip to content

Commit

Permalink
Merge pull request #114 from bwhmather/noop-class
Browse files Browse the repository at this point in the history
Don't reformat classes if statement order unchanged
  • Loading branch information
bwhmather authored Jan 29, 2024
2 parents 2d982f1 + 34fd40b commit dcb59fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ssort/_ssort.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def _key(statement):


def _statement_text_sorted_class(statement):
head_text, statements = split_class(statement)
head_text, unsorted_statements = split_class(statement)

statements = list(unsorted_statements)

# Take a snapshot of any hard dependencies between statements so that we can
# restore them later.
Expand Down Expand Up @@ -317,6 +319,9 @@ def _statement_text_sorted_class(statement):
sorted_statements, graph=runtime_graph
)

if sorted_statements == unsorted_statements:
return statement.text

return (
head_text
+ "\n"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ssort.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,19 @@ def _notdep(self):
)
actual = ssort(original)
assert actual == expected


def test_single_line_dummy_function():
original = "def fun(): ...\n"
expected = "def fun(): ...\n"

actual = ssort(original)
assert actual == expected


def test_single_line_dummy_class():
original = "class Class: ...\n"
expected = "class Class: ...\n"

actual = ssort(original)
assert actual == expected

0 comments on commit dcb59fd

Please sign in to comment.