Skip to content

indent=Tab setting not respected #2693

Description

@clayote

I have an .isort.cfg in my project's root directory. Under [settings], I've tried setting indent to

  • a literal tab character
  • the tab character between quotes
  • \t
  • \\t
  • Tab
  • tab
    isort 9.0.2 only ever indents with spaces. I tried the -i option on the command line, too -- no tabs.

Activity

  1. pradip-pawar1 commented on Sep 30, 2026

    @pradip-pawar1

    I've confirmed this. Using .isort.cfg with [settings] and indent=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.cfg values may be reaching combined_config through a different path than expected, or something upstream is altering them before this code runs.

    Still investigating.

  2. shan3520 commented on Oct 2, 2026

    @shan3520

    I dug into this on main (9.0.3.dev) and the 9.0.2 wheel. Findings:

    1. Tab / "tab" / TAB do work. indent=Tab in .isort.cfg gives config.indent == "\t" both via isort.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, so indent isn't used at all. The hanging-indent modes (2, 3, 4, 5, 8, 10, e.g. profile=black) do emit tabs. @clayote, does adding multi_line_output=3 fix it for you?

    3. Two real bugs I found along the way:

    • indent=\t in a config file is taken literally, so isort writes \tname, into the output, which is a SyntaxError.
    • A literal tab character as the value is stripped by configparser, leaving indent="", and isort silently writes unindented continuation lines.

    Proposed fix, if you're happy with it:

    • interpret \t in the indent value as a tab
    • reject an empty or whitespace-stripped-to-empty indent with a clear error instead of producing unindented output
    • document in the indent option that it accepts tab, a number of spaces, or a string, and that it only applies to the hanging-indent multi_line_output modes

    I'm happy to open a PR for this. (I used Claude to help investigate and reproduce this; I've verified the results.)

  3. pradip-pawar1 commented on Oct 2, 2026

    @pradip-pawar1

    I've opened a PR with a fix and regression test: #2704

  4. clayote commented on Oct 6, 2026

    @clayote
    Author

    On 9.0.2, multi_line_output=3 still gets me spaces, but in 9.0.3.dev11, I get the tabs I wanted. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions