You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function scopes also support constraints. Constraints are restrictions on the values a local variable may take. For example, take the following code:
def f(x: Union[int, None]) -> None:
dump_value(x) # Union[int, None]
if x is not None:
dump_value(x) # int
In this code, the x is not None check is translated into a constraint that is stored in the local scope, similar to how assignments are stored. When a variable is used within the block, we look at active constraints to restrict the type. In this example, this makes pyanalyze able to understand that within the if block the type of x is int, not Union[int, None].
The text was updated successfully, but these errors were encountered:
From pyanalyze:
Function scopes also support constraints. Constraints are restrictions on the values a local variable may take. For example, take the following code:
In this code, the x is not None check is translated into a constraint that is stored in the local scope, similar to how assignments are stored. When a variable is used within the block, we look at active constraints to restrict the type. In this example, this makes pyanalyze able to understand that within the if block the type of x is int, not Union[int, None].
The text was updated successfully, but these errors were encountered: