feat(typing): Enable mypy strict_equality in our strongly typed config#108606
feat(typing): Enable mypy strict_equality in our strongly typed config#108606
Conversation
| assert GrantCacheStatus.NEGATIVE_CACHE == "negative_cache" | ||
| assert GrantCacheStatus.VALID_WINDOW == "valid_window" | ||
| assert GrantCacheStatus.EXPIRED_WINDOW == "expired_window" | ||
| assert GrantCacheStatus.CACHE_MISS.value == "cache_miss" |
There was a problem hiding this comment.
unrelated to this PR, but curious about python enums and .value notation.
My understanding was that this is specifically meant to be for the default enums, and IntEnum / StrEnum could be accessed safely w/o .value?
(maybe this is just one of the python-isms i can't get used to, why do you need the .value when it already has the key?)
There was a problem hiding this comment.
Good thing to flag. This is, depending who you ask, a mypy bug or a Python typing spec bug.
I've seen https://discuss.python.org/t/amend-pep-586-to-make-enum-values-subtypes-of-literal/59456/9, python/mypy#16327, and a few others.
But, I believe this issue is limited to subclass enum to literal comparisons, which should be rare in practice (as the enum is intended to take the role of a literal).
So, as I understand it, a niche case with a fairly straightforward workaround (.value) that will probably go away or can be made to go away.
(I did look into updating our mypy plugin to fix these, but it wasn't trivial and didn't seem worth it)
#108606) strict_equality occasionally seems a bit picky, but it flags nonsense comparisons that can be tricky to identify otherwise. On average, it seems to make us safer and more honest without too much cost, and this in turn makes us able to move faster. See also: * #108478 * #108466 * #108462 * #108450 * #108448 * #108578
strict_equality occasionally seems a bit picky, but it flags nonsense comparisons that can be tricky to identify otherwise.
On average, it seems to make us safer and more honest without too much cost, and this in turn makes us able to move faster.
See also: