Skip to content

Commit

Permalink
change fix-assert-tuple codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Jan 23, 2024
1 parent 9cd27c3 commit 5953722
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ class DocMetadata:
),
"remove-assertion-in-pytest-raises": DocMetadata(
importance="Low",
guidance_explained="We believe this change is safe and will not cause any issues.",
),
"fix-assert-tuple": DocMetadata(
importance="Medium",
guidance_explained="We believe this change is safe and will not cause any issues.",
guidance_explained="An `assert` statement on a non-empty tuple is likely unintended and should be rewritten. However, the new change may result in assertion failures that should be reviewed.",
),
}

Expand Down
4 changes: 1 addition & 3 deletions src/core_codemods/docs/pixee_python_fix-assert-tuple.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
An assertion on a non-empty tuple will always evaluate to `True` so it's likely to be written unintentionally. This codemod will write one assert statement for each item in the tuple.


An assertion on a non-empty tuple will always evaluate to `True`. This means that `assert` statements involving non-empty tuple literals are likely unintentional and should be rewritten. This codemod rewrites the original `assert` statement by creating a new `assert` for each item in the original tuple.

The changes from this codemod look like this:

Expand Down
8 changes: 3 additions & 5 deletions src/core_codemods/fix_assert_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
class FixAssertTuple(SimpleCodemod, NameResolutionMixin):
metadata = Metadata(
name="fix-assert-tuple",
summary="Fix Assert on Populated Tuple",
review_guidance=ReviewGuidance.MERGE_WITHOUT_REVIEW,
summary="Fix `assert` on Non-Empty Tuple Literal",
review_guidance=ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW,
references=[],
)
change_description = (
"Separate assertion on a populated tuple into multiple assert statements."
)
change_description = "Separate assertion on a non-empty tuple literal into multiple assert statements."

def leave_SimpleStatementLine(
self,
Expand Down

0 comments on commit 5953722

Please sign in to comment.