Skip to content

(🎁) New rule for suspect dict comprehension with static key #4857

@KotlinIsland

Description

@KotlinIsland

I recently ran into some code where the developer was expecting a create a dict with a single key and a value created by a generator comprehension. Instead they ended up with a dict comprehension with a single entry for the value:

data = ["some", "Data"]
out = {"key": value.upper() for value in data}
print(out)

Could a new inspection be added that detects the presence of a static key within a dict comprehension?

Expected:

data = ["some", "Data"]
out = {"key": value.upper() for value in data}  # error: Static value for key in dict comprehension.
print(out)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions