Skip to content

Doubled prefix operators "not" and "~" should not be used python:S2761 #25725

@DayneSorvisto

Description

@DayneSorvisto

Describe the bug

Only found one instance but should be worth improving since is in tutorial sections.

Calling the not or ~ prefix operator twice might be redundant: the second invocation undoes the first. Such mistakes are typically caused by accidentally double-tapping the key in question without noticing. Either this is a bug, if the operator was actually meant to be called once, or misleading if done on purpose. Calling not twice is commonly done instead of using the dedicated "bool()" builtin function. However, the latter one increases the code readability and should be used.

Steps/Code to Reproduce

a = 0
b = False

c = not not a # Noncompliant
d = ~~b # Noncompliant

Expected Results

Same functional result, true/false but improve readability.

Actual Results

Syntax and readability issue.

Versions

OS Windows 10, Python 3.8 Pandas 1.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions