You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--sort-reexports does not respect --profile=black #2280
Attempting to sort a multiline __all__ attribute that is longer than the line limit with isort . --sort-reexports --profile=black wraps the lines in a non-black compatible way:
I did some digging and it seems that code sorting (sort_reexports and the undocumented and quasi-untested sort comments # isort: list, # isort: unique-list, etc) is the only feature that uses isort.literal.assigments. This function relies on the Python stdlib pprint formatting, and completely ignores the config, except for line_length:
class ISortPrettyPrinter(PrettyPrinter):
"""an isort customized pretty printer for sorted literals"""
def __init__(self, config: Config):
super().__init__(width=config.line_length, compact=True)
There is no regard for the config.multi_line_output, config.include_trailing_comma, config.split_on_trailing_comma, and likely many more that I am not aware of as a first-time contributor.
I believe fixing this would require us to write our own formatting logic, since pprint does not support any of the configurable formatting features isort needs.
I would need the input of the developers here, since there are no tests to form a de facto specification, but I believe that code sorting should follow the Config formatting options, and the pprint logic should be dropped and an isort algorithm like the ones in isort.output should be used or custom written for it.
@timothycrosley Hi, sorry for the direct ping, I'm sure you're very busy! Would you have a moment to confirm my suspicions that the code_sorting logic is insufficient, and preapprove my attempts to rewrite it? If I have your green light I can get started on it.
I already have a PR open for fixing similar sort_reexport problems that would require your attention: #2283
Unfortunately not. I used isort 6.0.1 but this exact issue still persists. Does it work for you? Maybe I'm doing something wrong..
I think you mean #2283, right? But as far as I saw, it doesn't encounter this issue, does it?
@Helveg Timothy is currently not maintaining isort, but feel free to propose a fix in case you feel like, me and other contributors are applying latest changes.
No worries bud, I was just curious :P Take your time :)
I'd do it myself but when I took a look at the codebase... Well, let's say, it'd cost me more than a quiet weekend to work on it ^^
Hi, is there any update on this? Just tried it again with isort version 7 and the issue remains. If you can guide me, where I have to look, I could also try it myself.
Activity
Helveg commentedon Jul 28, 2024
I did some digging and it seems that code sorting (
sort_reexportsand the undocumented and quasi-untested sort comments# isort: list,# isort: unique-list, etc) is the only feature that usesisort.literal.assigments. This function relies on the Python stdlibpprintformatting, and completely ignores theconfig, except forline_length:There is no regard for the
config.multi_line_output,config.include_trailing_comma,config.split_on_trailing_comma, and likely many more that I am not aware of as a first-time contributor.I believe fixing this would require us to write our own formatting logic, since
pprintdoes not support any of the configurable formatting featuresisortneeds.I would need the input of the developers here, since there are no tests to form a de facto specification, but I believe that code sorting should follow the
Configformatting options, and thepprintlogic should be dropped and an isort algorithm like the ones inisort.outputshould be used or custom written for it.Helveg commentedon Aug 6, 2024
@timothycrosley Hi, sorry for the direct ping, I'm sure you're very busy! Would you have a moment to confirm my suspicions that the
code_sortinglogic is insufficient, and preapprove my attempts to rewrite it? If I have your green light I can get started on it.I already have a PR open for fixing similar
sort_reexportproblems that would require your attention: #2283Hope to hear from you, and have a good day
lord-haffi commentedon Mar 21, 2025
Hi @Helveg, just kindly asking, is there any update on this issue?
Helveg commentedon Mar 21, 2025
Yes, this was merged and released in version 6. Can you let me know if it works as expected in v6 for you? If so, I'll close the issue
lord-haffi commentedon Mar 21, 2025
Unfortunately not. I used isort 6.0.1 but this exact issue still persists. Does it work for you? Maybe I'm doing something wrong..
I think you mean #2283, right? But as far as I saw, it doesn't encounter this issue, does it?
staticdev commentedon Mar 22, 2025
@Helveg Timothy is currently not maintaining isort, but feel free to propose a fix in case you feel like, me and other contributors are applying latest changes.
Helveg commentedon Mar 22, 2025
Oh ok, sorry @lord-haffi I must've gotten my wires crossed :) If I have a quiet weekend I can take a look at this
lord-haffi commentedon Mar 22, 2025
No worries bud, I was just curious :P Take your time :)
I'd do it myself but when I took a look at the codebase... Well, let's say, it'd cost me more than a quiet weekend to work on it ^^
lord-haffi commentedon Nov 26, 2025
Hi, is there any update on this? Just tried it again with isort version 7 and the issue remains. If you can guide me, where I have to look, I could also try it myself.
fix: sort_reexports honors formatting config, not pprint (PyCQA#2280)
test: cover literal formatter edge branches (PyCQA#2280)
test: assert sort_reexports output is black-stable and idempotent (Py…
docs,test: note repr-fallback rationale and cover wrapped single-elem…
refactor: drop pprint from literal sorting, format dict config-aware …
fix: honor formatting config when sorting __all__ and literals (PyCQA…
fix: honor formatting config when sorting __all__ and literals (PyCQA…
fix: make sorted __all__ and literals black-compatible (PyCQA#2280)
fix: clamp sort_reexports rollback seek so check mode can't seek nega…
Merge pull request PyCQA#2576 from lord-haffi/issue/2280