Repository navigation
indent=Tab setting not respected #2693
Description
Activity
I've confirmed this. Using
.isort.cfgwith [settings] andindent=tab(plain, unquoted, lowercase) correctly produces a real tab character in output. However, every other form fails and silently falls back to 4 spaces:indent="tab"(quoted),indent=Tab(capitalized),indent=\t,indent=\\t,- and even a literal tab byte in the config value itself.
Tested on isort 9.0.2.dev20 (editable install from main), Windows 11.
I found existing tab-handling logic:
if "indent" in combined_config: indent = str(combined_config["indent"]) if indent.isdigit(): indent = " " * int(indent) else: indent = indent.strip("'").strip('"') if indent.lower() == "tab": indent = "\t" combined_config["indent"] = indent
This logic should handle the quoted and capitalized cases correctly by my reading, which suggests the
.isort.cfgvalues may be reachingcombined_configthrough a different path than expected, or something upstream is altering them before this code runs.Still investigating.
I dug into this on
main(9.0.3.dev) and the 9.0.2 wheel. Findings:1.
Tab/"tab"/TABdo work.indent=Tabin.isort.cfggivesconfig.indent == "\t"both viaisort.Config(settings_path=...)and the CLI. I couldn't reproduce the capitalised/quoted failures.2. The likely cause of "only ever spaces" is the wrap mode. With the default
multi_line_output(GRID), as well as VERTICAL and BACKSLASH_GRID, continuation lines are aligned to the opening bracket with spaces, soindentisn't used at all. The hanging-indent modes (2, 3, 4, 5, 8, 10, e.g.profile=black) do emit tabs. @clayote, does addingmulti_line_output=3fix it for you?3. Two real bugs I found along the way:
indent=\tin a config file is taken literally, so isort writes\tname,into the output, which is aSyntaxError.- A literal tab character as the value is stripped by
configparser, leavingindent="", and isort silently writes unindented continuation lines.
Proposed fix, if you're happy with it:
- interpret
\tin theindentvalue as a tab - reject an empty or whitespace-stripped-to-empty
indentwith a clear error instead of producing unindented output - document in the
indentoption that it acceptstab, a number of spaces, or a string, and that it only applies to the hanging-indentmulti_line_outputmodes
I'm happy to open a PR for this. (I used Claude to help investigate and reproduce this; I've verified the results.)
I've opened a PR with a fix and regression test: #2704
On 9.0.2,
multi_line_output=3still gets me spaces, but in 9.0.3.dev11, I get the tabs I wanted. Thanks!
I have an
.isort.cfgin my project's root directory. Under[settings], I've tried settingindentto\t\\tTabtabisort 9.0.2 only ever indents with spaces. I tried the
-ioption on the command line, too -- no tabs.