mypy
1e96fb72 - Better narrowing for enums and other types with known equality (#21281)

Commit
67 days ago
Better narrowing for enums and other types with known equality (#21281) Fixes #21187, fully fixes this comment https://github.com/python/mypy/issues/9003#issuecomment-778349487 (previously improved on in 1.20 narrowing changes) This diff adds general functionality that replaces a few different pieces of ad hoc logic: - The conservative enum handling is now generalised - We can get rid of the special cased logic for None when narrowing contains, it is fully subsumed by more general logic - We no longer rely on promotion behaviour to narrow numeric types correctly - Similarly, we now narrow bytes consistently, regardless of `--strict-bytes`. We also no longer have to mark memoryview and bytearray as having custom equality implementations. That is, it is a long term fix for #20701 Co-authored-by Codex
Author
Parents
Loading