Skip to content

Allow hasattr() function #2228

@Dresdn

Description

@Dresdn

What's wrong

WPS421 forbids calling some built-in functions, which includes hasattr().

How it should be

The function hasattr() should be allowed. There are certain scenarios where using hasattr() makes sense, and sometimes is even faster (as even outlined in the referenced video @ 13:34-14:15 mark)

For code readability, if hasattr(foo, 'bar'): is cleaner than if getattr(foo, 'bar', None):.

I believe there was an argument against using hasattr() in python2, but I don't believe the same argument is valid for python3.

Flake8 version and plugins

n/a

pip information

n/a

OS information

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions