Skip to content

string_processing: Handle overloaded operators when splitting long strings #2334

Closed

Description

@bbugyi200

I'm not sure how often pathlib.Path is used with the augmented assignment operator rather than the regular one (/) nor do I know how often the string would be long enough that it would need to be split but all that aside, /= can definitely appear with strings on the right-hand of the assignment operator too:

from pathlib import Path
x = Path.cwd()
x /= "directory/subdirectory/file.txt"

Originally posted by @jack1142 in #2312 (comment)

Activity

  1. changed the title [-]I'm not sure how often `pathlib.Path` is used with the augmented assignment operator rather than the regular one (`/`) nor do I know how often the string would be long enough that it would need to be split but all that aside, `/=` can definitely appear with strings on the right-hand of the assignment operator too:[/-] [+]Handle overloaded operators when splitting long strings[/+] on Jun 13, 2021
  2. felix-hilden commented on Jun 13, 2021

    @felix-hilden
    Collaborator

    Thanks for reporting! I think since these keep coming, we ought to consider the full set of possible operators.

  3. bbugyi200 commented on Jun 13, 2021

    @bbugyi200
    ContributorAuthor

    @jack1142 Raises a good point here. This issue of no current support for long string splitting with the /= operator extends to many other operators that are not traditionally supported by strings. In other words, since essentially any operator can be overloaded to support strings, we need to support them all.

  4. bbugyi200 commented on Jun 13, 2021

    @bbugyi200
    ContributorAuthor

    @felix-hilden Beat me by 19 seconds ;).

  5. added
    S: acceptedThe changes in this design / enhancement issue have been accepted and can be implemented
    on Jun 13, 2021
  6. JelleZijlstra commented on Jan 29, 2022

    @JelleZijlstra
    Collaborator

    To be more concrete, the problem here is:

    % black --line-length=20  --preview -c 'x /= "directory subdirectory file.txt"'
    x /= "directory subdirectory file.txt"
    

    This should split up the string literal to make it fit in 20 characters.

  7. added
    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.
    on Dec 19, 2022
  8. changed the title [-]Handle overloaded operators when splitting long strings[/-] [+]string_processing: Handle overloaded operators when splitting long strings[/+] on Jan 30, 2024
  9. ZXLyyds100 commented on Oct 18, 2026

    @ZXLyyds100
    Contributor

    Implemented in #5562, covering all 13 binary arithmetic/bitwise operators and
    all 13 augmented assignments rather than just /=. The change stays within
    the existing unstable string_processing feature.

    The PR includes operator/width-boundary regressions, %-precedence safeguards,
    documentation, and same-condition before/after CLI screenshots and a short
    recording. Local validation passed: 629 regular tests, 82 Jupyter tests,
    repository pre-commit, self-formatting and the strict docs build. The optional
    IPython skip in tox's no-Jupyter phase and the local environment/verification
    limits are documented in the PR. Hosted Actions still require maintainer
    approval; local results are not a claim of hosted CI or maintainer approval.

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

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.F: linebreakHow should we split up lines?F: stringsRelated to our handling of stringsS: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions