Skip to content

PLC1901 false positive in __bool__ methods #4282

@trag1c

Description

@trag1c
class X:
    val: str

    def __bool__(self) -> bool:
        return self.val != ""
$ ruff check test.py --select=PLC1901
test.py:5:28: PLC1901 `self.val != ""` can be simplified to `self.val` as an empty string is falsey
Found 1 error.

Trying to correct this to self.val will lead to an error:

TypeError: __bool__ should return bool, returned str

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions