Fix --sort-reexports crash when __all__ is immediately followed by another assignment#2473
Draft
Fix --sort-reexports crash when __all__ is immediately followed by another assignment#2473
__all__ is immediately followed by another assignment#2473Conversation
…assignment without blank line Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix isort parsing issue with __all__ and __version__
Fix --sort-reexports crash when Mar 10, 2026
__all__ is immediately followed by another assignment
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2473 +/- ##
==========================================
- Coverage 99.25% 99.03% -0.22%
==========================================
Files 40 40
Lines 3079 3117 +38
Branches 671 684 +13
==========================================
+ Hits 3056 3087 +31
- Misses 13 17 +4
- Partials 10 13 +3 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
sort_reexports=True, a multi-line__all__followed immediately by another assignment (e.g.__version__) without a blank line caused aValueError: too many values to unpackbecause the collector kept consuming lines past the end of the__all__block.Changes
isort/core.py: Added_net_open_brackets(line)helper that counts net open brackets while correctly ignoring brackets inside string literals and comments. Tracksreexport_bracket_depthacross collected lines; when depth reaches 0 the section is processed immediately rather than waiting for a blank line or EOF. Also fixedsplit("=", 1)in__all__detection to handle values containing=.isort/literal.py: Defensive fix —code.split("=", 1)instead ofcode.split("=").tests/unit/test_isort.py: Added tests for both multi-line and single-line__all__immediately followed by another assignment with no blank line.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.