Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reformat classes if statement order unchanged #114

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading