sourcery
sourcery copied to clipboard
missing-dict-items and remove-dict-keys interacting so I can't have no errors
Checklist
- [x] I have searched the Sourcery documentation for the issue, and found nothing
- [x] I have checked there are no open bugs referencing the same bug or problem
Description
I have a dictionary with tuples as keys, and I want to destructure those keys as I loop through them, like so:
things = {
("a", 1): [1, 2, 3],
("b", 2): [4, 5, 6],
("c", 5): [7, 8, 9]
}
for letter, number in things:
print(f"this {letter} is {number}")
The code above causes sourcery to suggest missing-dict-items, because it thinks I am trying to iterate through the keys and values of a dictionary, so it wants to add .items()
So I explicitly added a call to .keys(), and it suggested remove-dict-keys!
Debug Information
IDE Version: PyCharm 2022.2 (Professional Edition)
Sourcery Version: 0.12.6
Operating system and Version: macOS Monterey 12.2.1
Oh no! I'll have to think about the best way to resolve this.
For the moment to remove the error you can add a # sourcery skip: missing-dict-items comment to your function (or switch off this suggestion completely with the Sourcery - turn off this refactoring option).
https://docs.sourcery.ai/IDEs/PyCharm/#skip-a-suggestion
I think it would make sense to not suggest missing-dict-items if the keys of the dictionary have type tuple[A, B], ie tuples of length 2.
That's a good solution - unfortunately our type inference isn't yet capable of handling this. Might be a while before we can address it.