Skip to content

Fix spurious unreachable and disallow-any errors from deferred passes - #13575

Merged
hauntsaninja merged 1 commit into
python:masterfrom
Michael0x2a:spurious-errors-from-deferred-pass
Sep 2, 2022
Merged

Fix spurious unreachable and disallow-any errors from deferred passes#13575
hauntsaninja merged 1 commit into
python:masterfrom
Michael0x2a:spurious-errors-from-deferred-pass

Conversation

@Michael0x2a

Copy link
Copy Markdown
Collaborator

This diff:

For more concise repros of these various issues, see the modified test files. But in short, there were two broad categories of errors:

  1. Within the deferred pass, we tend to infer 'Any' for the types of different variables instead of the actual type. This interacts badly with our unreachable and disallow-any checks and causes spurious errors.

    Arguably, the better way of handling this error is to only collect errors during the final pass. I briefly experimented with this
    approach, but was unable to find a clean, efficient, and non-disruptive way of implementing this. So, I settled for sprinkling in a few more not self.current_node_deferred checks.

  2. The self.msg.disallowed_any_type(...) call is normally guarded behind a not self.chk.current_node_deferred check. However, we were bypassing this check for except block assignments because we were deliberately setting that flag to False to work around some bug. For more context, see [WIP] Fix bug with exception variable reuse in deferred node. #2290.

    It appears we no longer need this patch anymore. I'm not entirely sure why, but I'm guessing we tightened and fixed the underlying problem with deferred passes some time during the past half-decade.

@github-actions

This comment has been minimized.

This diff:
- Fixespython#8129
- Fixespython#13043
- Fixespython#13167
For more concise repros of these various issues, see the modified
test files. But in short, there were two broad categories of errors:
1. Within the deferred pass, we tend to infer 'Any' for the types of
different variables instead of the actual type. This interacts
badly with our unreachable and disallow-any checks and causes
spurious errors.
Arguably, the better way of handling this error is to only collect
errors during the final pass. I briefly experimented with this
approach, but was unable to find a clean, efficient, and
non-disruptive way of implementing this. So, I settled for
sprinkling in a few more `not self.current_node_deferred` checks.
2. The 'self.msg.disallowed_any_type(...)` call is normally guarded
behind a `not self.chk.current_node_deferred` check. However, we
were bypassing this check for `except` block assignments because
we were deliberately setting that flag to False to work around some
bug. For more context, see python#2290.
It appears we no longer need this patch anymore. I'm not entirely
sure why, but I'm guessing we tightened and fixed the underlying
problem with deferred passes some time during the past half-decade.
@Michael0x2a
Michael0x2aforce-pushed the spurious-errors-from-deferred-pass branch from 19c3869 to 3eb30a8CompareSeptember 2, 2022 12:59
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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