Skip to content

Report incorrect assigning of dictionary entries with a colon (:) #312

@dannysepler

Description

@dannysepler

Consider the following code

dct = {
    'a': 1,
}
dct['b']: 2
print(dct)  # {'a': 1}

This is actually valid python syntax, because it is typing the 'b' entry as a 2 type. But we can assume the user meant to assign an element rather than type it (especially if there's no equal on this line).

(Recommended I post this to bugbear by pyflakes maintainers here: PyCQA/pyflakes#756)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions