Skip to content

PYI013 fix deletes comments #19385

@dscorbett

Description

@dscorbett

Summary

The fix for ellipsis-in-non-empty-class-body (PYI013) can remove comments, which is unnecessary and unsafe. Example:

$ cat >pyi013.py <<'# EOF'
class C:
    x = 1
    ...  # comment
# EOF

$ ruff --isolated check pyi013.py --select PYI013 --diff
--- pyi013.py
+++ pyi013.py
@@ -1,3 +1,2 @@
 class C:
     x = 1
-    ...  # comment

Would fix 1 error.

Compare unnecessary-placeholder (PIE790), which safely doesn’t delete the comment.

$ ruff --isolated check pyi013.py --select PIE790 --diff
--- pyi013.py
+++ pyi013.py
@@ -1,3 +1,3 @@
 class C:
     x = 1
-    ...  # comment
+    # comment

Would fix 1 error.

Version

ruff 0.12.3 (5bc81f2 2025-07-11)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions