The same module or name is imported twice in one scope
What it finds
A second import of the same name in the same block does nothing new; it is usually left over from merging two edits. Compared are the imports that are direct statements of the same module body, function body or class body, by the module and the name they bind. Imports in if, try and other blocks, which often choose between alternatives, are not compared.
From the rule's source, duplicate_import.rs.
import osimport sysimport ostx0 reports: os is imported a second timefrom json import loads, dumpsfrom json import loadstx0 reports: loads is imported a second time try: import simplejson as jsonexcept ImportError: import json def f(): import os return os Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:duplicate-import" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:duplicate-import] reason="..."tx0 explain tx0/python:duplicate-import shows the same in the terminal. Found a false positive? Report it.