Skip to content

add_import adds imports above module docstring when docstring is raw string #1893

Description

@Skylion007
  • I tried to use the add_import functionality like so:
    add_imports = "from __future__ import annotations"

However, it kept destroying my module level docstrings by adding an import before the """ string.
In the project I was working on, we use raw multiline stringsr""" which may be messing with the heuristics to detect module level docstrings here:

and not lstripped_line.startswith('"""')

As a temporary workaround, adding the append_only flag has seemed to fix it.

In short, isort will format my code like the following:

from __future__ import annotations
r"""module docstring
"""
from __future__ import annotations

Here is my isort config:

add_imports = "from __future__ import annotations"
# append_only = true # Enabling this is the workaround
profile = 'black'
treat_comments_as_code = "# %%"

Activity

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