mirror of
https://github.com/python/cpython.git
synced 2025-09-06 17:02:26 +00:00
PEP 3107 - Function Annotations thanks to Tony Lownds
This commit is contained in:
parent
f6657e67b3
commit
c150536b5e
32 changed files with 2855 additions and 1897 deletions
|
@ -233,7 +233,12 @@ class SymbolVisitor:
|
|||
if parent.nested or isinstance(parent, FunctionScope):
|
||||
scope.nested = 1
|
||||
self.scopes[node] = scope
|
||||
self._do_args(scope, node.argnames)
|
||||
|
||||
args = node.arguments
|
||||
for kwonly in node.kwonlyargs:
|
||||
args.append(kwonly.arg)
|
||||
self._do_arguments(scope, args)
|
||||
|
||||
self.visit(node.code, scope)
|
||||
self.handle_free_vars(scope, parent)
|
||||
|
||||
|
@ -275,16 +280,18 @@ class SymbolVisitor:
|
|||
if parent.nested or isinstance(parent, FunctionScope):
|
||||
scope.nested = 1
|
||||
self.scopes[node] = scope
|
||||
self._do_args(scope, node.argnames)
|
||||
self._do_arguments(scope, node.arguments)
|
||||
self.visit(node.code, scope)
|
||||
self.handle_free_vars(scope, parent)
|
||||
|
||||
def _do_args(self, scope, args):
|
||||
for name in args:
|
||||
if type(name) == types.TupleType:
|
||||
self._do_args(scope, name)
|
||||
def _do_arguments(self, scope, arguments):
|
||||
for node in arguments:
|
||||
if isinstance(node, ast.SimpleArg):
|
||||
scope.add_param(node.name)
|
||||
if node.annotation:
|
||||
self.visit(node.annotation, scope)
|
||||
else:
|
||||
scope.add_param(name)
|
||||
self._do_arguments(scope, node.args)
|
||||
|
||||
def handle_free_vars(self, scope, parent):
|
||||
parent.add_child(scope)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue