Skip to content

Literals before imports sometimes aren't sorted #1792

Closed
@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:
    ...

Activity

added a commit that references this issue on Jul 28, 2021

Fixed #1792: Sorting literals sometimes ignored when placed on first …

915aa68
added a commit that references this issue on Jul 28, 2021

Merge pull request #1793 from PyCQA/issue/1792-fix-literal-sort-at-top

e625f8a
willfrey

willfrey commented on Jul 28, 2021

@willfrey
Author
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @timothycrosley@willfrey

        Issue actions

          Literals before imports sometimes aren't sorted · Issue #1792 · PyCQA/isort