Skip to content

Commit

Permalink
fix: annotated argument's var node type is explicit, not inferred (#…
Browse files Browse the repository at this point in the history
…17217)

Fixes #17216

During conversion from a standard library AST to the mypy AST, `Var`
nodes were being created inside `Argument` nodes without acknowledging
the presence of a type annotation, leading to the `Var` node's type as
being always set as *inferred*:


https://github.com/python/mypy/blob/fb31409b392c5533b25173705d62ed385ee39cfb/mypy/nodes.py#L988

This causes an error at

https://github.com/python/mypy/blob/fb31409b392c5533b25173705d62ed385ee39cfb/mypyc/irbuild/expression.py#L161-L164

The fix simply acknowledges any presence of a type annotation, so the
type of the relevant `Var` node is no longer considered inferred if an
annotation is present.
  • Loading branch information
bzoracler authored May 21, 2024
1 parent 99dd314 commit ca393dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ def make_argument(
if argument_elide_name(arg.arg):
pos_only = True

argument = Argument(Var(arg.arg), arg_type, self.visit(default), kind, pos_only)
argument = Argument(Var(arg.arg, arg_type), arg_type, self.visit(default), kind, pos_only)
argument.set_line(
arg.lineno,
arg.col_offset,
Expand Down

0 comments on commit ca393dd

Please sign in to comment.