Commit ec4c463
authored
Short term fix for bytes narrowing (#20704)
Fixes #20701 / see discussion there
Background:
- In #20492 I added code to treat
bytes, bytearray and memoryview as having custom `__eq__`, since they
can compare equal to values that are of other types. I did this based on
primer hits on draft versions of that PR
- In #20643 I rewrote the handling of
custom equality when narrowing. That fixed many issues, but regressed
the equivalent of `testNarrowingOptionalBytes` because we're now more
principled about custom `__eq__`. Perhaps interestingly the primer on
that PR is small and not controversial, so I didn't feel the need to
prioritise unsound things
However, we only need one of the operands to have custom equality to
model these things as reachable, so I think we can probably just remove
`builtins.bytes` from here.
This behaviour still isn't ideal. For instance, narrowing here shouldn't
depend on whether we promote or not (we shouldn't narrow `v_all` to
bytes)
The real fix is adding more dedicated special casing so that we have an
in-between option between "narrow assuming we can only compare equal to
values of the same type" and "assume `__eq__` means we can't conclude
anything about the positive case"
Other relevant PRs:
- #20673 attempts to remove the other
custom eq logic for list, dict, set I added in #20492 . It should be
close to mergeable
- #20660 improves reachability and
unfortunately to land it I have to do a rethink for how int, float,
complex narrowing works. I actually think the current version has pretty
good semantics and the primer is valid (but scary). But I want to think
about it more1 parent bf7fe09 commit ec4c463
2 files changed
+77
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8637 | 8637 | | |
8638 | 8638 | | |
8639 | 8639 | | |
8640 | | - | |
8641 | 8640 | | |
8642 | 8641 | | |
8643 | 8642 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3498 | 3498 | | |
3499 | 3499 | | |
3500 | 3500 | | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
| 3520 | + | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
| 3528 | + | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
0 commit comments