package pyre-ast
Module TaglessFinal.Statement
This module provides a type that represents a Python statement.
type ('alias, 'arguments, 'bin_op, 'except_handler, 'expr, 'identifier, 'keyword, 'location, 'match_case, 'type_param, 'with_item, 'stmt)
t =
private {function_def : location:'location -> name:'identifier -> args:'arguments -> body:'stmt list -> decorator_list:'expr list -> returns:'expr option -> type_comment:string option -> type_params:'type_param list -> 'stmt;(*Represent a function definition (i.e.
def) statement.nameis the name of the function.argsis the argument list of the function (seeArguments).bodyis the body of the function.decorator_listis the list of decorators applied to the function.returnsis the (optionally specified) return annotation.type_commentis the Py2-style type comment for the function (seeParser.TaglessFinal.parse_function_type).type_params(optionally) specifies what type variables this function is generic against (seeTypeParam).
async_function_def : location:'location -> name:'identifier -> args:'arguments -> body:'stmt list -> decorator_list:'expr list -> returns:'expr option -> type_comment:string option -> type_params:'type_param list -> 'stmt;(*Represent an async function definition (i.e.
*)async def) statement. It has exactly the same set of fields asdefstatement.class_def : location:'location -> name:'identifier -> bases:'expr list -> keywords:'keyword list -> body:'stmt list -> decorator_list:'expr list -> type_params:'type_param list -> 'stmt;(*Represent a class definition (i.e.
class) statement.nameis the name of the class.basesis the positional arguments of the class' argument list (e.g. theBarpart inclass Foo(Bar): ...).keywordsis the keyword arguments of the class' argument list (e.g. themetaclass=FooMetapart inclass Foo(metaclass=FooMeta): ...). This is mainly used for metaclasses (see PEP 3115) but can also be used for other customizations of class creation (see PEP 487).bodyis the body of the class.decorator_listis the list of decorators applied to the function.type_params(optionally) specifies what type variables this function is generic against (seeTypeParam).
return : location:'location -> value:'expr option -> 'stmt;(*Represent a
returnstatement.valueis the (optionally specified) return value.
delete : location:'location -> targets:'expr list -> 'stmt;(*Represent a
deletestatement.targetsis the values to delete (guaranteed by CPython parser to be non-empty). Deletion can only be one of a selected few kinds of expressions, and the corresponding expression context will always be set toExpressionContext.t.del. See documentation ofExpressionContextfor more details of which expressions are allowed.
assign : location:'location -> targets:'expr list -> value:'expr -> type_comment:string option -> 'stmt;(*Represent an unannotated assignment statement.
targetsis the variables/attributes/subscripts to assign to (guaranteed by CPython parser to be non-empty). Assignment target can only be one of a selected few kinds of expressions, and the corresponding expression context will always be set toExpressionContext.t.store. See documentation ofExpressionContextfor more details of which expressions are allowed.valueis the value to be assigned totargets, i.e. the "right-hand-side" of the assignment.type_commentis the Py2-style type comment annotation fortargets. Note that iftargetscontains more than one element, then type comment is the only possible way to specify the annotation fortargetsas theann_assignstatement only supports inline annotation for a single target.
type_alias : location:'location -> name:'expr -> type_params:'type_param list -> value:'expr -> 'stmt;(*Represent a type alias statement. (see PEP 695)
nameis the name of the alias being assigned to. It's marked as an expression but in CPython implementation, it's always going to be anExpression.t.namewith context set toExpressionContext.t.store.type_paramsis the list of type variables this alias is generic against. For simple non-generic type alias definitions this is always going to be empty list.valueis the type to be assigned toname, i.e. the "right-hand-side" of the alias definition.
aug_assign : location:'location -> target:'expr -> op:'bin_op -> value:'expr -> 'stmt;(*Represent an augmented assignment statement (see PEP 203).
targetis the variable/attribute/subscript to assign to. Assignment target can only be one of a selected few kinds of expressions, and the corresponding expression context will always be set toExpressionContext.t.store. See documentation ofExpressionContextfor more details of which expressions are allowed.valueis the value that will be used to compute what needs to be assigned totarget. For an augmented assignmentx op= y, then "right-hand-side" of the assignment is computed asx op y.
ann_assign : location:'location -> target:'expr -> annotation:'expr -> value:'expr option -> simple:bool -> 'stmt;(*Represent an annotated assignment statement (see PEP 526).
targetis the variable/attribute/subscript to assign to. Assignment target can only be one of a selected few kinds of expressions, and the corresponding expression context will always be set toExpressionContext.t.store. See documentation ofExpressionContextfor more details of which expressions are allowed.valueis the value to be assigned totarget, i.e. the "right-hand-side" of the assignment. It can be unset (e.g.x: int), in which case the statement will only serve annotation purpose.simpleis set totruewhentargetis anameexpression that do not appear in between parenthesis, andfalseotherwise.
for_ : location:'location -> target:'expr -> iter:'expr -> body:'stmt list -> orelse:'stmt list -> type_comment:string option -> 'stmt;(*Represent a
forstatement.targetis the "index variable" of the statement. It can only be one of a selected few kinds of expressions, and the corresponding expression context will always be set toExpressionContext.t.store. See documentation ofExpressionContextfor more details of which expressions are allowed.iteris the expression that is being iterated on.bodyis the body of the loop.orelseis the list of statements that will be executed when the loop finishes.type_commentis the Py2-style type comment annotation fortarget. Note that type comment is the only possible way to directly specify the annotation fortargets. Achieving the same result with inline type annotation requires one to precede the loop with an annotation-onlyann_assignstatement.
async_for : location:'location -> target:'expr -> iter:'expr -> body:'stmt list -> orelse:'stmt list -> type_comment:string option -> 'stmt;(*Represent an
*)async forstatement. It has exactly the same set of fields asforstatement.while_ : location:'location -> test:'expr -> body:'stmt list -> orelse:'stmt list -> 'stmt;(*Represent a
whilestatement.testis the loop condition.bodyis the body of the loop.orelseis the list of statements that will be executed when the loop finishes.
if_ : location:'location -> test:'expr -> body:'stmt list -> orelse:'stmt list -> 'stmt;(*Represent a
ifstatement.testis the branch condition.bodyis the true-branch of the loop.orelseis the false-branch of the loop.
with_ : location:'location -> items:'with_item list -> body:'stmt list -> type_comment:string option -> 'stmt;(*Represent a
withstatement. See PEP 343.itemsis the "context expression" which will be evaluated to obtain a context manager.bodyis the body of thewithblock.type_commentis the Py2-style type comment annotation for all targets in the with items. Note that type comment is the only possible way to directly specify the annotation fortargets. Achieving the same result with inline type annotation requires one to precede the with block with annotation-onlyann_assignstatements.
async_with : location:'location -> items:'with_item list -> body:'stmt list -> type_comment:string option -> 'stmt;(*Represent an
*)async withstatement. It has exactly the same set of fields aswithstatement.match_ : location:'location -> subject:'expr -> cases:'match_case list -> 'stmt;raise_ : location:'location -> exc:'expr option -> cause:'expr option -> 'stmt;(*Represent a
raisestatement.excis the exception to raise. It can be left unset, in which case Python runtime will re-raise the "last" exception that was just caught.causeis set if one specify the "from" clause. For example,raise x from ywill setcausetoy, making the Python runtime attachyto the__cause__field ofx.
try_ : location:'location -> body:'stmt list -> handlers:'except_handler list -> orelse:'stmt list -> finalbody:'stmt list -> 'stmt;(*Represent a
try...exceptstatement.bodyis the body of the try block, i.e. the logic to run in the normal case.handlersis a list of exception handlers, specifying the logic to run in the exceptional cases.orelseis the list of statements that will be executed when the body finishes without having any exception raised and without early return/continue/break.finalbodyis the list of statements that is guaranteed to be executed when execution leaves the try block, regardless of whether an exception occured or not.
try_star : location:'location -> body:'stmt list -> handlers:'except_handler list -> orelse:'stmt list -> finalbody:'stmt list -> 'stmt;(*Represent a
try...except*statement. See PEP 654.Arguments here means the same thing as the
*)try...exceptstatement, except that thehandlerspart should be interpreted as catching&handling exception groups.assert_ : location:'location -> test:'expr -> msg:'expr option -> 'stmt;(*Represent an
assertstatement.testis condition to assert on.msgis an (optionally specified) argument that will be passed to theAssertionErrorbeing raised by the Python runtime, if the assertion fails.
import : location:'location -> names:'alias list -> 'stmt;(*Represent an
importstatement.nameis the list of module names to import.
import_from : location:'location -> module_:'identifier option -> names:'alias list -> level:int -> 'stmt;(*Represent a
from ... import ...statement.module_is the name of the module from which we want to import. It can be left unset, when no module name is specified (e.g.from . import X).namesis the list of names to import to the current module.levelis an integer holding the level of the relative import (i.e. the number of dots in the import target).
global : location:'location -> names:'identifier list -> 'stmt;(*Represent a
globalstatement.namesis a list of names in the current block to declare as global.
nonlocal : location:'location -> names:'identifier list -> 'stmt;(*Represent a
nonlocalstatement. See PEP 3104.namesis a list of names in the current block to declare as nonlocal.
expr : location:'location -> value:'expr -> 'stmt;(*Represent an expression statement.
valueholds the expression (usually with side-effects) that will be evaluated.
pass : location:'location -> 'stmt;(*Represent a
*)passstatement.break : location:'location -> 'stmt;(*Represent a
*)breakstatement.continue : location:'location -> 'stmt;(*Represent a
*)continuestatement.
}val make :
function_def:
(location:'a ->
name:'b ->
args:'c ->
body:'d list ->
decorator_list:'e list ->
returns:'e option ->
type_comment:string option ->
type_params:'f list ->
'd) ->
async_function_def:
(location:'a ->
name:'b ->
args:'c ->
body:'d list ->
decorator_list:'e list ->
returns:'e option ->
type_comment:string option ->
type_params:'f list ->
'd) ->
class_def:
(location:'a ->
name:'b ->
bases:'e list ->
keywords:'g list ->
body:'d list ->
decorator_list:'e list ->
type_params:'f list ->
'd) ->
return:(location:'a -> value:'e option -> 'd) ->
delete:(location:'a -> targets:'e list -> 'd) ->
assign:
(location:'a ->
targets:'e list ->
value:'e ->
type_comment:string option ->
'd) ->
type_alias:(location:'a -> name:'e -> type_params:'f list -> value:'e -> 'd) ->
aug_assign:(location:'a -> target:'e -> op:'h -> value:'e -> 'd) ->
ann_assign:
(location:'a ->
target:'e ->
annotation:'e ->
value:'e option ->
simple:bool ->
'd) ->
for_:
(location:'a ->
target:'e ->
iter:'e ->
body:'d list ->
orelse:'d list ->
type_comment:string option ->
'd) ->
async_for:
(location:'a ->
target:'e ->
iter:'e ->
body:'d list ->
orelse:'d list ->
type_comment:string option ->
'd) ->
while_:(location:'a -> test:'e -> body:'d list -> orelse:'d list -> 'd) ->
if_:(location:'a -> test:'e -> body:'d list -> orelse:'d list -> 'd) ->
with_:
(location:'a ->
items:'i list ->
body:'d list ->
type_comment:string option ->
'd) ->
async_with:
(location:'a ->
items:'i list ->
body:'d list ->
type_comment:string option ->
'd) ->
match_:(location:'a -> subject:'e -> cases:'j list -> 'd) ->
raise_:(location:'a -> exc:'e option -> cause:'e option -> 'd) ->
try_:
(location:'a ->
body:'d list ->
handlers:'k list ->
orelse:'d list ->
finalbody:'d list ->
'd) ->
try_star:
(location:'a ->
body:'d list ->
handlers:'k list ->
orelse:'d list ->
finalbody:'d list ->
'd) ->
assert_:(location:'a -> test:'e -> msg:'e option -> 'd) ->
import:(location:'a -> names:'l list -> 'd) ->
import_from:
(location:'a -> module_:'b option -> names:'l list -> level:int -> 'd) ->
global:(location:'a -> names:'b list -> 'd) ->
nonlocal:(location:'a -> names:'b list -> 'd) ->
expr:(location:'a -> value:'e -> 'd) ->
pass:(location:'a -> 'd) ->
break:(location:'a -> 'd) ->
continue:(location:'a -> 'd) ->
unit ->
('l, 'c, 'h, 'k, 'e, 'b, 'g, 'a, 'j, 'f, 'i, 'd) tConstructor of t.