Skip to content

Calling isort with --sort-reexports with input from stdin fails #2393

Closed

Description

@ipvych

Output of isort --version: 6.0.1

Steps to reproduce

echo 'from test import A, B
__all__ = ["A", "B"]' > test.py
isort --sort-reexports - < test.py

Result

Traceback (most recent call last):
  File "/usr/bin/isort", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3.13/site-packages/isort/main.py", line 1146, in main
    api.sort_stream(
    ~~~~~~~~~~~~~~~^
        input_stream=input_stream,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
        raise_on_skip=False,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/isort/api.py", line 211, in sort_stream
    changed = core.process(
        input_stream,
    ...<3 lines>...
        raise_on_skip=raise_on_skip,
    )
  File "/usr/lib/python3.13/site-packages/isort/core.py", line 139, in process
    output_stream.seek(output_stream.tell() - reexport_rollback)
                       ~~~~~~~~~~~~~~~~~~^^
io.UnsupportedOperation: underlying stream is not seekable

Activity

  1. added a commit that references this issue on Jun 22, 2025
    716aaa8
  2. DanielNoord commented on Mar 12, 2026

    @DanielNoord
    Member

    #2399 attempts to fix this, but I'm wondering if we should just make this an error.

    The code of sort-reexports simply does not work well with non-seekable streams. It seems simpler to just disallow this?

  3. added theissue type on Mar 12, 2026
  4. Abdu-Ahmed commented on May 24, 2026

    @Abdu-Ahmed
    Contributor

    Hiya folks!

    i've opened a PR that fixes this: #2547

    The fix adds a seekability check in api.sort_stream() before calling core.process() , if sort_reexports is enabled and the output stream is not seekable, it swaps in an internal StringIO buffer, following the same pattern already used for non-readable streams in the atomic code path.

  5. DanielNoord commented on May 26, 2026

    @DanielNoord
    Member

    @Abdu-Ahmed Did you see my comment above? Unfortunately on your branch CI fails as well.

  6. added a commit that references this issue on May 28, 2026
    df3d9b8
  7. Abdu-Ahmed commented on May 28, 2026

    @Abdu-Ahmed
    Contributor

    hey there!
    thanks for the feedback, updated per your feedback, instead of silently buffering, the fix now raises a clear ValueError when --sort reexports is used with a non-seekable stream. Also fixed the E302 and W292 lint issues.

  8. DanielNoord commented on May 28, 2026

    @DanielNoord
    Member

    Please read the full issue. You are wasting other people's time...

  9. added a commit that references this issue on Jun 1, 2026
    9d40646
  10. Abdu-Ahmed commented on Jun 1, 2026

    @Abdu-Ahmed
    Contributor

    hey there daniel!

    i apologize but i didn't mean to waste anyone's time, was trying to make some helpful contribution that's all, anyways hopefully this update fits the bill here, the check is now at the CLI level in main.py, raising a clear error when --sort-reexports is used with stdin ('-'), following the same pattern as the existing show_files check. The api.py change has been reverted.

  11. added 3 commits that reference this issue on Jun 2, 2026
    8b45039
    442e3a3
    d72a1eb
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions