fixhunt

ruff UP010

labelled unknown
Runs / 2026-10-17T21-14-42-088Z-y9rb-ruff-UP010ruff 0.17.12026-10-17 21:14 UTC8 programs × 2 round(s)16 programs, 1 fired, 1 fixed, 0 findings, 0 rejectedmodel cost $0.0046

Analysis Nemotron 3 Super

Flags any imported name from `__future__` when the target Python version already includes that feature by default.

Fix: Removes the entire `from __future__ import ...` statement, leaving surrounding code and whitespace unchanged except for the deletion of that line.

12 hazards
  • Deleting a trailing comment on the same line as the import removes that comment, altering source documentation.
  • If the `__future__` import is the only thing keeping a module-level variable alive (e.g., via side effect), removing it may change initialization behavior.
  • In rare cases where a future import suppresses a SyntaxWarning (e.g., bare `except:`), removal could resurface the warning.
  • If the import is inside a conditional block that never executes, removing it changes the module's abstract syntax tree but not runtime behavior—still, tools relying on static structure may be affected.
  • When the import is followed by a blank line that is part of a docstring or block comment grouping, deleting the import line may visually merge sections, misleading readers.
  • If a linter or tool expects the `__future__` import to be present to determine feature availability (e.g., for type checking), removing it may cause false positives.
  • In Python 2.x environments where the feature is not actually available, removing the import would cause a runtime error—but the rule assumes target-version >= feature availability.
  • If the import line contains a line continuation (`\`) that also serves another purpose (e.g., in a multi-statement line), removing it could cause a syntax error.
  • When the import is used to suppress a future-warning in development mode, removing it may re-enable noisy warnings during execution.
  • If the module relies on the import to affect the behavior of `eval` or `exec` calls within the same module, removing it changes how those functions interpret code.
  • In notebooks or interactive environments where `__future__` imports affect cell semantics, removal may alter execution across cells.
  • If the import is aliased (e.g., `from __future__ import annotations as ann`), the rule does not fire, but if it did, removing it would break the alias—however, the rule correctly does not flag aliased imports.

Programs

idresulttitlehazard
r1-p001silent prediction offModule-level variable kept alive by future import side effectIf the `__future__` import is the only thing keeping a module-level variable alive (e.g., via side effect), removing it may change initialization behavior.
r1-p002silentAliased future import (rule does not fire)If the import is aliased (e.g., `from __future__ import annotations as ann`), the rule does not fire, but if it did, removing it would break the alias—however, the rule correctly does not flag aliased
r1-p003silent prediction offTool expects future import for feature detectionIf a linter or tool expects the `__future__` import to be present to determine feature availability (e.g., for type checking), removing it may cause false positives.
r1-p004silent prediction offExceptions in finally/else chains after import removalexceptions raised inside the rewritten code, finally/else clauses, exception chaining
r1-p005silent prediction offFuture import inside never-executed conditional blockIf the import is inside a conditional block that never executes, removing it changes the module's abstract syntax tree but not runtime behavior—still, tools relying on static structure may be affected
r1-p006silent prediction offContext manager with write() but no close()context managers that are not files, objects with write() but no close()
r1-p007silent prediction offLine continuation in future import serving dual purposeIf the import line contains a line continuation (`\`) that also serves another purpose (e.g., in a multi-statement line), removing it could cause a syntax error.
r1-p008silent prediction offpathlib vs os.path behavior with relative pathspathlib vs os.path behavior on relative paths, symlinks, missing files, bytes paths
r2-p001silent prediction offTrailing Comment HazardDeleting a trailing comment on the same line as the import removes that comment, altering source documentation.
r2-p002fix okSyntaxWarning ResurgenceIn rare cases where a future import suppresses a SyntaxWarning (e.g., bare `except:`), removal could resurface the warning.
r2-p003silent prediction offWalrus and Comprehension Scopingwalrus, comprehensions scoping, late binding in closures and lambdas
r2-p004silent prediction offClass Attributes and Descriptorsclass attributes vs instance attributes, descriptors, properties with side effects
r2-p005silent prediction offStar Imports and Module Side Effectsstar-imports, module-level side effects, __all__
r2-p006silent prediction offMutable Default Argumentsmutable default arguments and aliasing after a rewrite
r2-p007silentPython 2.x Runtime ErrorIn Python 2.x environments where the feature is not actually available, removing the import would cause a runtime error—but the rule assumes target-version >= feature availability.
r2-p008silentNever-Executed Conditional BlockIf the import is inside a conditional block that never executes, removing it changes the module's abstract syntax tree but not runtime behavior—still, tools relying on static structure may be affected

Sources

r1-p001 · Module-level variable kept alive by future import side effect
1# This import triggers evaluation of __future__ annotations, which creates _Feature object
2from __future__ import annotations
3
4# Variable exists only because the import caused __future__ module to be loaded
5# and we access a side-effect attribute
6try:
7 x = __import__('__future__').annotations._Feature.value
8 print(f'x = {x}')
9except AttributeError as e:
10 print(f'AttributeError: {e}')
AttributeError: '_Feature' object has no attribute '_Feature'
r1-p002 · Aliased future import (rule does not fire)
1# Rule does not trigger on aliased imports
2from __future__ import annotations as ann
3
4# If the rule incorrectly fired and removed this, 'ann' would be undefined
5try:
6 print(f'ann = {ann}')
7except NameError as e:
8 print(f'NameError: {e}')
ann = _Feature((3, 7, 0, 'beta', 1), None, 16777216)
r1-p003 · Tool expects future import for feature detection
1from __future__ import annotations
2
3# Simulate a tool that checks for __future__ import presence via AST or module inspection
4# We use a side effect: accessing __future__.annotations to simulate tool reliance
5import sys
6if 'annotations' in dir(__import__('__future__')):
7 print('Tool sees: annotations feature available')
8else:
9 print('Tool sees: annotations feature NOT available')
10
11# At runtime, annotations is always available in Python 3.7+, but tool may misbehave
12# if it relies on the import line being present
13print('Runtime: using annotations in type hint')
14def f() -> int: # This line may be misparsed by tool if import removed
15 return 42
16print(f())
Tool sees: annotations feature available
Runtime: using annotations in type hint
42
r1-p004 · Exceptions in finally/else chains after import removal
1from __future__ import annotations
2
3try:
4 print('In try')
5 raise ValueError('test')
6except ValueError as e:
7 print(f'Caught: {e}')
8 raise RuntimeError('from value') from e
9else:
10 print('In else')
11finally:
12 print('In finally')
13 # This line may be affected if import removal changes line numbers in traceback
14 # but we check if the exception chain is preserved
15 pass
In try
Caught: test
In finally
r1-p005 · Future import inside never-executed conditional block
1if False:
2 from __future__ import annotations # Rule fires here (even though dead code)
3
4# Even though the import is never executed, removing it changes AST
5# Simulate a tool that scans for future imports statically
6import ast
7with open(__file__, 'r') as f:
8 tree = ast.parse(f.read())
9
10future_imports = [n for n in ast.walk(tree) if isinstance(n, ast.ImportFrom) and n.module == '__future__']
11print(f'Static future imports found: {len(future_imports)}')
12
13# Runtime behavior unchanged because block never runs
14print('Runtime: no future import executed')
r1-p006 · Context manager with write() but no close()
1from __future__ import annotations
2
3class WriteOnly:
4 def write(self, data):
5 print(f'WriteOnly.write: {data}')
6 def __enter__(self):
7 return self
8 def __exit__(self, exc_type, exc_val, exc_tb):
9 pass # No close()
10
11with WriteOnly() as w:
12 w.write('hello')
13 # The __future__ import above ensures annotations are enabled
14 # If removed, and we had type hints relying on it, this could break
15 # But here we just print to show flow
16print('Context manager done')
WriteOnly.write: hello
Context manager done
r1-p007 · Line continuation in future import serving dual purpose
1from __future__ import annotations \
2; print('line continuation used for multi-statement') # \) is part of import line
3
4# If rule removes the import line, it removes the \ too,
5# leaving:
6# ; print('line continuation used for multi-statement')
7# Which is invalid syntax (leading semicolon)
8# But we guard against actual syntax error by making it conditional
9# However, to show hazard: we simulate what happens if line is removed
10# We can't actually remove it and run, so we show intent via comment
11# Instead, we make the import line's presence affect a variable via side effect
12import sys
13if hasattr(sys, 'flags'):
14 print(f'Python flags: {sys.flags}')
15else:
16 print('No sys.flags')
17print('Import line processed')
line continuation used for multi-statement
Python flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=1, no_site=0, ignore_environment=1, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=1, dev_mode=False, utf8_mode=1, warn_default_encoding=0, safe_path=True, int_max_str_digits=4300)
Import line processed
r1-p008 · pathlib vs os.path behavior with relative paths
1from __future__ import annotations
2import os
3import pathlib
4
5# Create a temporary file
6open('temp.txt', 'w').close()
7
8# Use pathlib and os.path to show potential divergence if annotations affect type inference
9# (though they don't directly, we simulate reliance via type-hinted function)
10def get_path(p: str) -> pathlib.Path: # Annotation relies on __future__
11 return pathlib.Path(p)
12
13def get_os_path(p: str) -> str:
14 return os.path.abspath(p)
15
16p1 = get_path('temp.txt')
17p2 = get_os_path('temp.txt')
18print(f'pathlib: {p1.resolve()}')
19print(f'os.path: {p2}')
20
21# Clean up
22os.remove('temp.txt')
23print('Cleanup done')
pathlib: <wd>/prog
os.path: <wd>/prog
Cleanup done
r2-p001 · Trailing Comment Hazard
1from __future__ import annotations # keep this comment
2print('comment was here')
comment was here
r2-p002 · SyntaxWarning Resurgence
1from __future__ import print_function
2try:
3 pass
4except:
5 print('caught')
6finally:
7 print('done')
--- orig.py	2026-10-17 17:15:03.414670336 -0400
+++ fixed.py	2026-10-17 17:15:03.581657259 -0400
@@ -1,4 +1,3 @@
-from __future__ import print_function
 try:
     pass
 except:
done
r2-p003 · Walrus and Comprehension Scoping
1from __future__ import annotations
2f = []
3for i in range(2):
4 if (x := i) not in f:
5 f.append(x)
6 f.append(lambda: x)
7print([g() for g in f[2:]])
r2-p004 · Class Attributes and Descriptors
1from __future__ import annotations
2class A:
3 x = 1
4 def __init__(self):
5 self.y = self.x
6 @property
7 def z(self):
8 return self.y + 1
9print(A().z)
2
r2-p005 · Star Imports and Module Side Effects
1from __future__ import annotations
2import math
3__all__ = ['sqrt']
4def sqrt(x):
5 return math.sqrt(x)
6print(sqrt(4))
2.0
r2-p006 · Mutable Default Arguments
1from __future__ import annotations
2def f(a=[]):
3 a.append(1)
4 return a
5print(f())
6print(f())
[1]
[1, 1]
r2-p007 · Python 2.x Runtime Error
1try:
2 from __future__ import annotations
3except SyntaxError:
4 print('SyntaxError caught')
5print('continuing')
r2-p008 · Never-Executed Conditional Block
1if False:
2 from __future__ import annotations
3print('import not executed')