Skip to content

False negative for RUF019 with not operator #12285

@dscorbett

Description

@dscorbett

RUF019 checks for things like "key" in dct and dct["key"] in boolean contexts, like an if condition or the argument to bool. It should also detect it as the operand of not.

$ ruff --version
ruff 0.5.1
$ echo 'bool("key" in dct and dct["key"])' | ruff check --isolated --output-format=concise --select RUF019 /dev/stdin
/dev/stdin:1:6: RUF019 [*] Unnecessary key check before dictionary access
Found 1 error.
[*] 1 fixable with the `--fix` option.
$ echo 'not ("key" in dct and dct["key"])' | ruff check --isolated --output-format=concise --select RUF019 /dev/stdin
All checks passed!

Metadata

Metadata

Assignees

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