ruff RUF100
labelled unknown
Analysis Nemotron 3 Super
Flags unnecessary 'noqa' inline comments where none of their listed error codes correspond to actual lint errors present on that line.
Fix: Removes the entire '# noqa: <codes>' comment from the end of the line, preserving any preceding code and whitespace up to but not including the comment.
8 hazards
- If the line contains only a 'noqa' comment (e.g., '# noqa: F401'), removing it deletes the entire line, potentially altering indentation-sensitive structures like multi-line statement continuations or changing the line count for debugging tools.
- If the 'noqa' comment is followed by additional text on the same line without a separating '#', that text is incorrectly interpreted as part of the suppression and deleted, which could remove user intent such as explanations or other tool configurations (e.g., turning '# noqa: F401 temporary fix' into just the code prefix).
- In cases where multiple space-separated tokens follow the 'noqa' comment on the same line (e.g., '# noqa: F401 # some note'), the fix may delete too much or too little depending on how Ruff tokenizes the line, risking partial deletion of adjacent comments or code.
- If the 'noqa' comment appears inside a string literal (e.g., msg = "ignore this: # noqa: F401"), the rule should not fire, but if it did due to a parsing error, removing it would corrupt the string content and potentially change runtime behavior.
- When the 'noqa' comment is the only content on a line that serves as a visual separator in a block of code (e.g., between function definitions), removing it may reduce readability but does not affect execution; however, if the line is relied upon by tools that parse source structure (like coverage.py or IDEs), its removal could interfere with those tools.
- If the line ends with a 'noqa' comment and has trailing whitespace, the fix preserves the whitespace, but in rare cases where whitespace is syntactically significant (e.g., in certain DSLs or when generating code via string concatenation), its preservation might still contribute to unintended behavior—though this is extremely unlikely in standard Python.
- If the 'noqa' comment suppresses an error that is actually present but masked by a conditional import or platform-specific code (e.g., inside a TYPE_CHECKING block), removing the comment could cause the linter to re-flag the error, but this does not change runtime behavior—only lint output.
- In files processed by other tools that expect the 'noqa' comment to remain (e.g., for audit trails or compliance), its removal could violate external requirements even though the Python semantics are unchanged.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r2-p001 | fix ok | Hazard 1: Line containing only noqa comment | If the line contains only a 'noqa' comment (e.g., '# noqa: F401'), removing it deletes the entire line, potentially altering indentation-sensitive structures like multi-line statement continuations or |
| r2-p002 | fix ok | Hazard 2: bytes vs str, encoding and newline handling | bytes vs str, encoding and newline handling, text vs binary modes |
| r2-p003 | fix ok | Hazard 3: Multiple space-separated tokens after noqa comment | In cases where multiple space-separated tokens follow the 'noqa' comment on the same line (e.g., '# noqa: F401 # some note'), the fix may delete too much or too little depending on how Ruff tokenizes |
| r2-p004 | fix ok | Hazard 4: class attributes vs instance attributes, descriptors, properties with side effects | class attributes vs instance attributes, descriptors, properties with side effects |
| r2-p005 | fix ok | Hazard 5: evaluation order and side effects when expressions are merged, duplicated or deleted | evaluation order and side effects when expressions are merged, duplicated or deleted |
| r2-p006 | fix ok prediction off | Hazard 6: noqa suppressing actual error masked by conditional import | If the 'noqa' comment suppresses an error that is actually present but masked by a conditional import or platform-specific code (e.g., inside a TYPE_CHECKING block), removing the comment could cause t |
| r2-p007 | fix ok | Hazard 7: comments and docstrings attached to the removed or moved code | comments and docstrings attached to the removed or moved code |
| r2-p008 | fix ok | Hazard 8: context managers that are not files, objects with write() but no close() | context managers that are not files, objects with write() but no close() |
Sources
r2-p001 · Hazard 1: Line containing only noqa comment
1x = '\\'
2# noqa: F401
3print(repr(x))
--- orig.py 2026-10-17 17:49:50.597206066 -0400 +++ fixed.py 2026-10-17 17:49:50.760232015 -0400 @@ -1,3 +1,2 @@ x = '\\' -# noqa: F401 print(repr(x))
'\\'
r2-p002 · Hazard 2: bytes vs str, encoding and newline handling
1with open('test.bin', 'wb') as f:
2 f.write(b'hello') # noqa: SIM115
3with open('test.bin', 'rb') as f:
4 print(f.read())
5import os; os.remove('test.bin')
--- orig.py 2026-10-17 17:49:50.861248093 -0400 +++ fixed.py 2026-10-17 17:49:51.033275467 -0400 @@ -1,5 +1,5 @@ with open('test.bin', 'wb') as f: - f.write(b'hello') # noqa: SIM115 + f.write(b'hello') with open('test.bin', 'rb') as f: print(f.read()) import os; os.remove('test.bin')
b'hello'
r2-p003 · Hazard 3: Multiple space-separated tokens after noqa comment
1x = 1 # noqa: F841 # unused but used later
2y = x + 2
3print(y)
--- orig.py 2026-10-17 17:49:51.139292315 -0400 +++ fixed.py 2026-10-17 17:49:51.298317588 -0400 @@ -1,3 +1,3 @@ -x = 1 # noqa: F841 # unused but used later +x = 1 # unused but used later y = x + 2 print(y)
3
r2-p004 · Hazard 4: class attributes vs instance attributes, descriptors, properties with side effects
1class C:
2 attr = 1 # noqa: F841
3 @property
4 def prop(self):
5 return self.attr
6c = C()
7print(c.prop)
--- orig.py 2026-10-17 17:49:51.400333801 -0400 +++ fixed.py 2026-10-17 17:49:51.557358756 -0400 @@ -1,5 +1,5 @@ class C: - attr = 1 # noqa: F841 + attr = 1 @property def prop(self): return self.attr
1
r2-p005 · Hazard 5: evaluation order and side effects when expressions are merged, duplicated or deleted
1def f():
2 print('side effect')
3 return 1
4x = f() # noqa: F841
5print(x)
--- orig.py 2026-10-17 17:49:51.657374651 -0400 +++ fixed.py 2026-10-17 17:49:51.820400560 -0400 @@ -1,5 +1,5 @@ def f(): print('side effect') return 1 -x = f() # noqa: F841 +x = f() print(x)
side effect 1
r2-p006 · Hazard 6: noqa suppressing actual error masked by conditional import
1from typing import TYPE_CHECKING
2if TYPE_CHECKING:
3 import os # noqa: F401
4print('runtime safe')
--- orig.py 2026-10-17 17:49:51.914415501 -0400 +++ fixed.py 2026-10-17 17:49:52.091443613 -0400 @@ -1,4 +1,4 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - import os # noqa: F401 + import os print('runtime safe')
runtime safe
r2-p007 · Hazard 7: comments and docstrings attached to the removed or moved code
1def f():
2 """Docstring."""
3 x = 1 # noqa: F841
4 # inline note
5 return x
6print(f())
--- orig.py 2026-10-17 17:49:52.196460277 -0400 +++ fixed.py 2026-10-17 17:49:52.363486781 -0400 @@ -1,6 +1,6 @@ def f(): """Docstring.""" - x = 1 # noqa: F841 + x = 1 # inline note return x print(f())
1
r2-p008 · Hazard 8: context managers that are not files, objects with write() but no close()
1import io
2buf = io.StringIO()
3with buf as s:
4 s.write('hello') # noqa: SIM115
5print(buf.getvalue())
--- orig.py 2026-10-17 17:49:52.462502493 -0400 +++ fixed.py 2026-10-17 17:49:52.841562642 -0400 @@ -1,5 +1,5 @@ import io buf = io.StringIO() with buf as s: - s.write('hello') # noqa: SIM115 + s.write('hello') print(buf.getvalue())