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

fix(python): type-checking may require incorrect type #3820

Merged
merged 2 commits into from
Nov 2, 2022

Commits on Nov 2, 2022

  1. fix(python): type-checking may require incorrect type

    Since dae724c, Python type-checking
    relies on a nested stub function as a type annotations source. The
    parameter signature of that stub was copied verbatim from the
    surrounding function, including any forward type references.
    
    However, the forward references can safely be replaced with regular type
    references as the module is guaranteed to be fully loaded by the time
    the stub is created, and using forward-references there results in
    `typeguard` possibly evaluating those in a different context than the
    one where the surrounding function was defined. The consequence of this
    is that multiple different foward references by the same name may be
    incorrectly treated as referring to the same type, despite coming from
    different modules.
    
    This is fixed by turning forward type references in the stub with
    regular type references (in other words, removing any `"` from the
    parameter signature of the stub), which lets the type be resolved from
    the local definition context instead of the final runtime context in
    which the function is called.
    
    Fixes #3818
    RomainMuller committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    f173c72 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4fe0d34 View commit details
    Browse the repository at this point in the history