ruff RUF103
labelled unknown
Analysis Nemotron 3 Super
Flags inline `# ruff: disable` comments without any specified error codes.
Fix: Replace the comment with `# ruff: disable[]` when no codes were provided; preserve all other text on the line including indentation and trailing whitespace/comments after the suppression marker.
12 hazards
- The fix removes meaningful trailing content if the line had additional non-whitespace text after `# ruff: disable` (e.g., `# ruff: disable TODO`), altering program semantics by deleting that text.
- If the suppression comment was the only content on a line, replacing it with `# ruff: disable[]` adds characters that could affect tools relying on exact line length or column counts (e.g., language server protocols).
- In a multiline string or docstring, the literal text `# ruff: disable` is not a comment; the fix would incorrectly alter the string value, changing runtime behavior.
- If the line contains other comments after the suppression marker (e.g., `# ruff: disable # note`), the fix preserves them but may misalign intent if the original spacing was semantically meaningful (though rare).
- When the suppression appears in a shebang line or encoding declaration (e.g., `# -*- coding: utf-8 #- ruff: disable`), the fix breaks the validity of that special line.
- If the file uses a custom Ruff configuration that treats `# ruff: disable` as valid via an extension or plugin, the fix enforces core Ruff behavior and may suppress intended custom handling.
- In generated code where line numbers are referenced elsewhere (e.g., in source maps or debug info), inserting `[]` shifts subsequent line content, potentially breaking those references.
- If the suppression comment is part of a larger token due to missing whitespace (e.g., `x=1# ruff:disable`), the fix does not add space and may produce invalid syntax like `x=1# ruff:disable[]`, which remains a comment but could confuse parsers expecting space before `#`.
- When the suppression is the last line of the file without a newline, adding `[]` may append without a newline, affecting tools that expect final newline.
- If the suppression comment is inside a bracketed expression split across lines (e.g., `[\n # ruff: disable]`), the fix alters the interior comment but does not affect the expression value, though it changes formatting.
- In a file interpreted by another tool that scans for `# ruff: disable` as a feature flag (not suppression), the fix changes the token to `# ruff: disable[]`, which may not be recognized, disabling the feature flag unintentionally.
- If the suppression comment is copied from documentation or example where the absence of codes is intentional for illustration, the fix modifies the example, making it less clear or incorrect.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p001 | fired, no fix | Trailing non-whitespace deletion | The fix removes meaningful trailing content if the line had additional non-whitespace text after '# ruff: disable' (e.g., '# ruff: disable TODO'), altering program semantics by deleting that text. |
| r1-p002 | fired, no fix | Custom Ruff configuration override | If the file uses a custom Ruff configuration that treats '# ruff: disable' as valid via an extension or plugin, the fix enforces core Ruff behavior and may suppress intended custom handling. |
| r1-p003 | fired, no fix | Feature flag misinterpretation | In a file interpreted by another tool that scans for '# ruff: disable' as a feature flag (not suppression), the fix changes the token to '# ruff: disable[]', which may not be recognized, disabling the |
| r1-p004 | fired, no fix | Final line newline sensitivity | When the suppression is the last line of the file without a newline, adding '[]' may append without a newline, affecting tools that expect final newline. |
| r1-p005 | invalid | Walrus and comprehension scoping interaction | walrus, comprehensions scoping, late binding in closures and lambdas |
| r1-p006 | fired, no fix | Source map line number shift | In generated code where line numbers are referenced elsewhere (e.g., in source maps or debug info), inserting '[]' shifts subsequent line content, potentially breaking those references. |
| r1-p007 | fired, no fix | Comment attachment preservation | comments and docstrings attached to the removed or moved code |
| r1-p008 | silent prediction off | File write truncation simulation | file modes and truncation, partial writes, non-str data passed to write |
Sources
r1-p001 · Trailing non-whitespace deletion
1# This line has a suppression followed by a TODO marker that should persist
2# But if the fix deletes 'TODO', the logic changes
3value = 42 # ruff: disable TODO
4if 'TODO' in __import__('inspect').getsource(lambda: value):
5 print('TODO preserved')
6else:
7 print('TODO deleted - semantics altered')
TODO preserved
r1-p002 · Custom Ruff configuration override
1# Custom plugin might interpret plain '# ruff: disable' as enabling strict mode
2# After fix, becomes '# ruff: disable[]' which plugin may ignore
3mode = 'lax'
4try:
5 exec("# ruff: disable\nif 1: mode = 'strict'")
6except:
7 pass
8print(f"Mode: {mode}")
Mode: strict
r1-p003 · Feature flag misinterpretation
1# Tool checks for '# ruff: disable' to enable verbose logging
2# Fix changes it to '# ruff: disable[]' which tool ignores
3verbose = False
4if '# ruff: disable' in open(__file__).read():
5 verbose = True
6print(f"Verbose logging: {verbose}")
Verbose logging: True
r1-p004 · Final line newline sensitivity
1# This is the last line of the file and has no newline
2# ruff: disable
r1-p005 · Walrus and comprehension scoping interaction (generated program does not parse: Traceback (most recent call last):)
1# Suppression inside comprehension affects walrus capture
2results = [(lambda: x)() for x in [1] if (tmp := 2) and True # ruff: disable]
3print(f"First result: {results[0] if results else 'none'}")
r1-p006 · Source map line number shift
1# Line 1: suppression
2# ruff: disable
3# Line 2: this line's number is referenced in debug info
4DEBUG_LINE = 2
5import inspect
6lines = inspect.getsourcelines(lambda: None)[0]
7actual_line = lines[DEBUG_LINE - 1].strip() if DEBUG_LINE <= len(lines) else "OUT_OF_RANGE"
8print(f"Line {DEBUG_LINE} content: {repr(actual_line)}")
Line 2 content: 'OUT_OF_RANGE'
r1-p007 · Comment attachment preservation
1def example():
2 """This docstring should stay attached to the function."""
3 x = 1 # ruff: disable
4 y = 2 # this comment explains y
5 return x + y
6print(f"Function docstring: {example.__doc__}")
Function docstring: This docstring should stay attached to the function.
r1-p008 · File write truncation simulation
1# Simulate writing to file where suppression fix alters byte count
2import os
3with open('test.txt', 'w') as f:
4 f.write('# ruff: disable') # exact bytes matter for truncation
5size = os.path.getsize('test.txt')
6print(f"File size: {size} bytes")
7os.remove('test.txt')
File size: 15 bytes