Skip to content

Maybe a problem with reachability of Match cases #12778

Description

@mrolle45

It appears to me that mypy could process case bodies following an always true pattern.

I noticed that reachability.py function infer_reachability_of_match_statement has the following:

line 76...
        if pattern_value in (ALWAYS_FALSE, MYPY_FALSE) \
                or guard_value in (ALWAYS_FALSE, MYPY_FALSE):
            # The case is considered always false, so we skip the case body.
            mark_block_unreachable(s.bodies[i])
        elif pattern_value in (ALWAYS_FALSE, MYPY_TRUE) \
                               ^^^^^^^^^^^^
                and guard_value in (ALWAYS_TRUE, MYPY_TRUE):
            for body in s.bodies[i + 1:]:
                mark_block_unreachable(body)

I would think that this ALWAYS_FALSE should be ALWAYS_TRUE, because you are determining whether the case [i] is always executed, so that the following cases are never executed.
Also, FWIW, pattern_value can never be ALWAYS_FALSE. It is either ALWAYS_TRUE or TRUTH_VALUE_UNKNOWN.
Please review this. If you determine that the code is correct, then please explain why, and then you can remove the (bug) label and close this issue. Otherwise, please make the indicated change.
Thanks.

Your Environment

  • Mypy version used: 0.950

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions