Skip to content

[New Rule] if k in d: del d[k] #195

@InSyncWithFoo

Description

@InSyncWithFoo

Explanation

When removing a key from a dictionary, there's no need to check for its existence, as the end results will be the same anyway. Thus, dict.pop(key, None) is preferred.

Also see this issue at @astral-sh/ruff.

Example

if key in dictionary:
    del dictionary[key]

# Good
dictionary.pop(key, None)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions