Skip to content

PLE1141 fix is suppressed for empty dict #21289

@dscorbett

Description

@dscorbett

Summary

The fix for dict-iter-missing-items (PLE1141) is suppressed when the relevant dict’s keys are all 2-tuples in its initial binding. This usually makes sense, but it doesn’t make sense when the dict is defined as empty. In that case, there is no reason to assume that any keys added later will be 2-tuples, and that is a rare pattern so they probably won’t be, so PLE1141 should allow the fix. If the empty dict is annotated to have 2-tuple keys, as in dict[tuple[int, str], bool], though, it is still appropriate to suppress the fix. Example:

$ cat >ple1141.py <<'# EOF'
data = {}
data["x"] = 1
for k, v in data:
    print(f"{k=} {v=}")
# EOF

$ ruff --isolated check ple1141.py --select PLE1141 --preview
All checks passed!

Version

ruff 0.14.3 (8737a2d 2025-10-30)

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresruleImplementing 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