Skip to content

Don't enforce superfluous-parens for default function values #8160

Open
@skirpichev

Description

@skirpichev

Bug description

Probably, using complex expressions as defaults is a kind of a bad practice, but the language does support this. I'm suggesting to relax the checker for such examples:

TEST = 1

def foo1(spam=(TEST == 0)):  # superfluous-parens
    return spam


def foo2(spam=TEST == 0):  # unreadable
    return spam


def foo3(spam= TEST == 0):  # only slightly better, but it's not PEP 8
    return spam


def foo4(spam= TEST == ((3 + 2))):  # but here we want C0325!
    return spam

(Last case, IIUIC, is #5361.)

Configuration

No response

Command used

pylint -s n --disable=all --enable=C0325 a.py

Pylint output

************* Module a
a.py:3:0: C0325: Unnecessary parens after '=' keyword (superfluous-parens)

Expected behavior

No error.

Pylint version

pylint 2.16.0
astroid 2.14.1
Python 3.11.1+ (heads/3.11:ba88628808, Jan 14 2023, 08:40:06) [GCC 10.2.1 20210110]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions