Skip to content

Disable consider-using-join for non-empty separator #8701

@vmeurisse

Description

@vmeurisse

Current problem

In 2.16.0, consider-using-join was extended to include non-empty separators. This makes pylint complains about the following code:

def test(values: List[str]):
    data = ""
    for value in values:
        data += f"prefix{value}suffix"
    return data

However I don't think the suggested refactor is an improvement: prefix and suffix are duplicated and the empty list case need to be handled specifically

def test(values: List[str]):
    if not values:
        return ""
    return "prefix" + "suffixprefix".join(values) + "suffix"

The current options are:

  • disable the rule completely. This has the drawback of loosing the previous rule for empty separators.
  • use a "pylint: disable" comment. However having to use this on regular basis creates bad habits and reduce the value of linting

Desired solution

Would it be possible to have an option to disable the rule only for the non-empty separator case?

Additional context

No response

Metadata

Metadata

Assignees

Labels

Enhancement ✨Improvement to a componentGood first issueFriendly and approachable by new contributorsHelp wanted 🙏Outside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions