本文整理汇总了Python中ast.AsyncFunctionDef方法的典型用法代码示例。如果您正苦于以下问题:Python ast.AsyncFunctionDef方法的具体用法?Python ast.AsyncFunctionDef怎么用?Python ast.AsyncFunctionDef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ast
的用法示例。
在下文中一共展示了ast.AsyncFunctionDef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _has_return
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _has_return(fun):
# type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> bool
"""Return true if the function has a fruitful return.
Args:
fun: A function node to check.
Returns:
True if there is a fruitful return, otherwise False.
"""
def skip(f):
return f != fun and isinstance(f, FunctionDef)
for node in _walk(fun, skip):
if isinstance(node, ast.Return) and node.value is not None:
return True
return False
示例2: _get_decorator_names
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _get_decorator_names(fun): # type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> List[str] # noqa: E501
"""Get decorator names from the function.
Args:
fun: The function whose decorators we are getting.
Returns:
The names of the decorators. Does not include setters and
getters.
"""
ret = list()
for decorator in fun.decorator_list:
# Attributes (setters and getters) won't have an id.
if hasattr(decorator, 'id'):
ret.append(getattr(decorator, 'id'))
return ret
示例3: get_line_number_from_function
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def get_line_number_from_function(fn):
# type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> int
"""Get the line number for the end of the function signature.
The function signature can be farther down when the parameter
list is split across multiple lines.
Args:
fn: The function from which we are getting the line number.
Returns:
The line number for the start of the docstring for this
function.
"""
line_number = fn.lineno
if hasattr(fn, 'args') and fn.args.args:
last_arg = fn.args.args[-1]
line_number = last_arg.lineno
return line_number
示例4: get_source
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def get_source(self):
"""
Get a string containing the Python source code corresponding to the
statements in the block.
Returns:
A string containing the source code of the statements.
"""
src = ""
for statement in self.statements:
if type(statement) in [ast.If, ast.For, ast.While]:
src += (astor.to_source(statement)).split('\n')[0] + "\n"
elif type(statement) == ast.FunctionDef or\
type(statement) == ast.AsyncFunctionDef:
src += (astor.to_source(statement)).split('\n')[0] + "...\n"
else:
src += astor.to_source(statement)
return src
示例5: _generate_nodes
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _generate_nodes(parent, level=0, breadcrumb=''):
nodes = []
for child in parent.body:
if isinstance(child, ast.ClassDef):
style = OutlineNodeItem.Style.cls
elif isinstance(child, ast.FunctionDef) or isinstance(child, ast.AsyncFunctionDef):
style = OutlineNodeItem.Style.fn
else:
style = None
if style:
node = OutlineNodeItem(style, child.name, child.lineno, child.col_offset, level, breadcrumb)
nodes.append(node)
if breadcrumb:
bc = '{} • {}'.format(breadcrumb, child.name)
else:
bc = child.name
child_nodes = OutlineDataSource._generate_nodes(child, level + 1, bc)
if child_nodes:
nodes.extend(child_nodes)
return nodes
示例6: check_for_b012
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def check_for_b012(self, node):
def _loop(node, bad_node_types):
if isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef)):
return
if isinstance(node, (ast.While, ast.For)):
bad_node_types = (ast.Return,)
elif isinstance(node, bad_node_types):
self.errors.append(B012(node.lineno, node.col_offset))
for child in ast.iter_child_nodes(node):
_loop(child, bad_node_types)
for child in node.finalbody:
_loop(child, (ast.Return, ast.Continue, ast.Break))
示例7: getAdjacentClassScopes
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def getAdjacentClassScopes (self, inMethod = False):
# Work backward until finding an interruption in the chain
# Needed to fix destructuring assignment in nested classes and to make super () work
# The latter needs inMethod, since supported use of super () is directly or indirectly enclosed in a method body
reversedClassScopes = []
for scope in reversed (self.scopes):
if inMethod:
if type (scope.node) in (ast.FunctionDef, ast.AsyncFunctionDef):
continue
else:
inMethod = False
if type (scope.node) != ast.ClassDef:
break
reversedClassScopes.append (scope)
return reversed (reversedClassScopes)
示例8: _visit_fn_def
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _visit_fn_def(self: 'ASTTagger', node: Union[ast.FunctionDef, ast.AsyncFunctionDef]):
self.symtable.entered.add(node.name)
args = node.args
visit_suite(self.visit, node.decorator_list)
visit_suite(self.visit, args.defaults)
visit_suite(self.visit, args.kw_defaults)
if node.returns:
node.returns = self.visit(node.returns)
new = self.symtable.enter_new()
if isinstance(node, ast.AsyncFunctionDef):
new.cts.add(ContextType.Coroutine)
arguments = args.args + args.kwonlyargs
if args.vararg:
arguments.append(args.vararg)
if args.kwarg:
arguments.append(args.kwarg)
for arg in arguments:
annotation = arg.annotation
if annotation:
self.visit(annotation)
new.entered.add(arg.arg)
new_tagger = ASTTagger(new)
node.body = [new_tagger.visit(each) for each in node.body]
return Tag(node, new)
示例9: def_rewrite
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def def_rewrite(mark: Tokenizer,
name: Tokenizer,
args: ast.arguments,
ret: ast.AST,
body: list,
is_async: bool = False):
name = name.value
ty = ast.AsyncFunctionDef if is_async else ast.FunctionDef
return ty(name, args, body, [], ret, **loc @ mark)
示例10: _get_arguments
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _get_arguments(fn):
# type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> Tuple[List[str], List[str]] # noqa: E501
arguments = list() # type: List[str]
types = list() # type: List[str]
def add_arg_by_name(name, arg):
arguments.append(name)
if arg.annotation is not None and hasattr(arg.annotation, 'id'):
types.append(arg.annotation.id)
else:
types.append(None)
for arg in fn.args.args:
add_arg_by_name(arg.arg, arg)
for arg in fn.args.kwonlyargs:
add_arg_by_name(arg.arg, arg)
# Handle single-star arguments.
if fn.args.vararg is not None:
name = '*' + fn.args.vararg.arg
add_arg_by_name(name, fn.args.vararg)
if fn.args.kwarg is not None:
name = '**' + fn.args.kwarg.arg
add_arg_by_name(name, fn.args.kwarg)
return arguments, types
示例11: _walk
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _walk(fun, skip):
# type: (Union[ast.FunctionDef, ast.AsyncFunctionDef], Callable) -> Iterator[ast.AST] # noqa: E501
"""Walk through the nodes in this function, skipping as necessary.
ast.walk goes through nodes in an arbitrary order, and doesn't
allow you to skip an entire branch (as far as I know.) This
function will perform an in-order breadth-first traversal, and will
skip unnecessary branches.
Args:
fun: The function to walk.
skip: A function which returns True if we should skip the current
node and all of its children.
Yields:
Children of the function and the function itself.
"""
queue = deque() # type: deque
queue.appendleft(fun)
while len(queue) > 0:
curr = queue.pop()
if skip(curr):
continue
if hasattr(curr, 'body'):
queue.extendleft(curr.body)
if hasattr(curr, 'handlers'):
queue.extendleft(curr.handlers)
if hasattr(curr, 'orelse'):
queue.extendleft(curr.orelse)
yield curr
示例12: _has_yield
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _has_yield(fun): # type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> bool # noqa: E501
for node in ast.walk(fun):
if isinstance(node, ast.Yield) or isinstance(node, ast.YieldFrom):
return True
return False
示例13: _get_all_functions
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _get_all_functions(tree): # type: (ast.AST) -> Iterator[Union[ast.FunctionDef, ast.AsyncFunctionDef]] # noqa: E501
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
yield node
elif hasattr(ast, 'AsyncFunctionDef'):
if isinstance(node, ast.AsyncFunctionDef):
yield node
示例14: _is_classmethod
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _is_classmethod(fun): # type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> bool # noqa: E501
return 'classmethod' in _get_decorator_names(fun)
示例15: _is_staticmethod
# 需要导入模块: import ast [as 别名]
# 或者: from ast import AsyncFunctionDef [as 别名]
def _is_staticmethod(fun): # type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> bool # noqa: E501
return 'staticmethod' in _get_decorator_names(fun)