Skip to content

Literals before imports sometimes aren't sorted #1792

@willfrey

Description

@willfrey

I just discovered the sorted literals feature, which is fantastic. One behavior I'm noticing is that if you have a literal before any imports, then isort doesn't appear to pick up on that literal.

The following example won't have __all__ sorted:

"""I'm a docstring! Look at me!"""

# isort: unique-list
__all__ = ["Foo", "Foo", "Bar"]

from typing import final  # arbitrary


@final
class Foo:
    ...


@final
class Bar:
    ...

However, these two examples appear to be fine and will have __all__ sorted correctly.

# Some top-level comment before the docstring.
# Maybe it's a copyright. It's probably a copyright.

"""I'm a docstring! Look at me!"""

# isort: unique-list
__all__ = ["Foo", "Foo", "Bar"]

from typing import final  # arbitrary


@final
class Foo:
    ...


@final
class Bar:
    ...
"""I'm a docstring! Look at me!"""

from __future__ import annotations

# isort: unique-list
__all__ = ["Foo", "Foo", "Bar"]

from typing import final  # arbitrary


@final
class Foo:
    ...


@final
class Bar:
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions