Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mypyc] Use correct rtype for variable with inferred optional type #15206

Merged
merged 2 commits into from
Jun 2, 2023

Commits on May 7, 2023

  1. [mypyc] Use correct rtype for variable with inferred optional type

    ```python
    def f(b: bool) -> None:
        if b:
            y = 1
        else:
            y = None
    
    f(False)
    ```
    
    On encountering y = 1, mypyc uses the expression type to determine the
    variable rtype. This usually works (as mypy infers the variable type
    based on the first assignment and doesn't let it change afterwards),
    except in this situation.
    
    NameExpr(y)'s type is int, but the variable should really be int | None.
    Fortunately, we can use the Var node's type information which is
    correct... instead of blindly assuming the first assignment's type is
    right.
    ichard26 committed May 7, 2023
    Configuration menu
    Copy the full SHA
    032f2d8 View commit details
    Browse the repository at this point in the history

Commits on May 27, 2023

  1. Configuration menu
    Copy the full SHA
    f433dda View commit details
    Browse the repository at this point in the history