synt.stmt
¤
assertion
¤
Assert
¤
Bases: Statement
The assert
statement.
Examples:
References
Source code in synt/stmt/assertion.py
__init__
¤
|
Initialize the assertion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
The expression to assert. |
required |
msg |
IntoExpression | None
|
The assert message. |
None
|
Source code in synt/stmt/assertion.py
indented
¤
assign
¤
Assignment
¤
Bases: Statement
Assignment statement.
Examples:
Source code in synt/stmt/assign.py
__init__
¤
|
Initialize a new assignment statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
The variable to be assigned to. |
required |
type
¤
|
Set the target's type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression
|
The type of the target variable. |
required |
assign
¤
|
Set the target's value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v |
IntoExpression
|
The value of the assignment. |
required |
indented
¤
Source code in synt/stmt/assign.py
block
¤
Block
¤
Bases: Statement
A Python code block.
Source code in synt/stmt/block.py
__init__
¤
branch
¤
Branch
¤
Bases: Statement
The branch statement, aka if ... elif ... else
.
Examples:
References
If
.
Source code in synt/stmt/branch.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
tests
instance-attribute
¤
|
Branches of the statement, including if
and elif
.
__init__
¤
elif_
¤
|
Create a new branch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
Expression to test. |
required |
else_
¤
Add a fallback branch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
List of statements. |
()
|
indented
¤
Source code in synt/stmt/branch.py
BranchBuilder
¤
A single branch builder for the branch statement.
Source code in synt/stmt/branch.py
__init__
¤
|
Initialize a branch builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
Branch
|
The parent node. |
required |
test |
IntoExpression
|
The expression to test. |
required |
if_
¤
|
Initialize a new branch statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
The expression to test. |
required |
References
cls
¤
ClassDef
¤
Bases: Statement
Class definition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
class BarT: @abstractmethod def baz(self, a: T) -> str: return f"Bar({a}).baz"'''
1 2 3 4 5 6 7 8 9 |
|
Source code in synt/stmt/cls.py
ckwargs
instance-attribute
¤
|
Class keyword arguments.
E.g., meta classes.
__init__
¤
|
Initialize a function definition.
DO NOT USE THIS IN YOUR CODE!
Source code in synt/stmt/cls.py
indented
¤
Source code in synt/stmt/cls.py
ClassDefBuilder
¤
Class definition builder.
References
Source code in synt/stmt/cls.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
ckwargs
instance-attribute
¤
|
Class keyword arguments.
E.g., meta classes.
__init__
¤
decorator
¤
|
Append a decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator |
IntoExpression
|
Decorator to append. |
required |
dec
¤
|
class_
¤
|
type_param
¤
|
Add generic type parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
TypeParam | Identifier
|
Type parameters to add. |
()
|
Source code in synt/stmt/cls.py
__getitem__
¤
|
Alias type_param
.
Source code in synt/stmt/cls.py
arg
¤
|
Add arguments for the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
IntoExpression | tuple[Identifier, IntoExpression]
|
Arguments to add. |
()
|
**kwargs |
IntoExpression
|
Keyword arguments to add with their default values. |
{}
|
Source code in synt/stmt/cls.py
__call__
¤
|
block
¤
Set the block of the class, and build it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*statements |
Statement
|
Statements to include in the class body. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If the required fields ( |
Source code in synt/stmt/cls.py
class_
¤
|
Initialize a class without decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Class name. |
required |
context
¤
WithItem
¤
Bases: IntoCode
An item of the with
statement.
References
Source code in synt/stmt/context.py
asname
instance-attribute
¤
|
__init__
¤
|
Initialize a new with
item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context |
IntoExpression
|
The context expression. |
required |
as_
¤
|
Set the alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asname |
IntoExpression
|
The alias for the context expression. |
required |
With
¤
Bases: Statement
The with
statement.
Examples:
```python with_stmt = with_(id_("a"), (id_("b"), id_("b2")), with_item(id_("c")).as_(id_("c2"))).block( PASS ) assert with_stmt.into_code() == "with a, b as b2, c as c2:
pass" ```
References:
With
.
Source code in synt/stmt/context.py
__init__
¤
Initialize a with
statement.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
list[WithItem]
|
|
required |
body |
Block
|
Statement block. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in synt/stmt/context.py
indented
¤
WithBuilder
¤
The builder for With
.
Source code in synt/stmt/context.py
__init__
¤
|
Initialize a with
statement.
The items
's item could be either WithItem
object, an expression-like or a tuple:
- WithItem
: Save as-is.
- Expression-like: Convert into a WithItem
without any alias.
- tuple[IntoExpression, IntoExpression]
: The first element is the context, and the second is the alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
WithItem | IntoExpression | tuple[IntoExpression, IntoExpression]
|
|
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in synt/stmt/context.py
decorator
¤
DecoratorGroup
¤
A group of decorators.
Source code in synt/stmt/decorator.py
__init__
¤
|
Initialize a decorator and create a new group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator |
IntoExpression
|
The decorator to add. |
required |
dec
¤
|
Append a new decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator |
IntoExpression
|
The decorator to add. |
required |
class_
¤
|
Initialize a class with the decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the class. |
required |
def_
¤
|
Initialize a function with the decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the function. |
required |
async_def
¤
|
Initialize an async function with the decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the function. |
required |
delete
¤
Delete
¤
Bases: Statement
The del
statement.
Examples:
References
Source code in synt/stmt/delete.py
__init__
¤
|
Initialize the delete statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
The expression to be deleted. |
required |
expression
¤
ExprStatement
¤
Bases: Statement
A statement that only contains a single expression.
Examples:
Source code in synt/stmt/expression.py
__init__
¤
|
Initialize a nwe statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr |
IntoExpression
|
Inner expression. |
required |
fn
¤
FnArg
¤
Bases: IntoCode
Function argument.
Examples:
References
arg
.
Source code in synt/stmt/fn.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
annotation
instance-attribute
¤
|
Argument annotation.
default_expr
instance-attribute
¤
|
Argument default expression.
is_vararg
instance-attribute
¤
Whether the argument is a variable argument, or *args
.
is_kwarg
instance-attribute
¤
Whether the argument is a keyword argument, or **kwargs
.
__init__
¤
|
Initialize a new argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Argument keyword. |
required |
annotation |
IntoExpression | None
|
Argument annotation. |
None
|
default |
IntoExpression | None
|
Default value for the argument. |
None
|
is_vararg |
bool
|
Whether the argument is a variable argument, or |
False
|
is_kwarg |
bool
|
Whether the argument is a keyword argument, or |
False
|
Source code in synt/stmt/fn.py
vararg
¤
kwarg
¤
annotate
¤
|
Add annotation for the argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation |
IntoExpression
|
Argument annotation. |
required |
ty
¤
|
default
¤
|
Set the default value of the argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default |
IntoExpression
|
Default value for the argument. |
required |
into_code
¤
Source code in synt/stmt/fn.py
FunctionDef
¤
Bases: Statement
Function definition.
Examples:
With dsl-like aliases:
With raw ast:
References
Source code in synt/stmt/fn.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
__init__
¤
|
Initialize a function definition.
DO NOT USE THIS IN YOUR CODE!
Source code in synt/stmt/fn.py
indented
¤
Source code in synt/stmt/fn.py
FunctionDefBuilder
¤
Function definition builder.
References
Source code in synt/stmt/fn.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
__init__
¤
async_
¤
decorator
¤
|
Append a decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator |
IntoExpression
|
Decorator to append. |
required |
dec
¤
|
def_
¤
|
async_def
¤
|
Initialize an async function.
This is equivalent to self.async_().def_(name)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Function name. |
required |
type_param
¤
|
Add generic type parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
TypeParam | Identifier
|
Type parameters to add. |
()
|
Source code in synt/stmt/fn.py
__getitem__
¤
|
Alias type_param
.
Source code in synt/stmt/fn.py
arg
¤
|
Add arguments for the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
FnArg | Identifier
|
Arguments to add. |
()
|
**kwargs |
IntoExpression
|
Keyword arguments to add with their default values. |
{}
|
Source code in synt/stmt/fn.py
__call__
¤
|
returns
¤
|
Set the return type of the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
returns |
IntoExpression
|
Return type of the function. |
required |
block
¤
|
Set the block of the function, and build it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*statements |
Statement
|
Statements to include in the function body. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If the required fields ( |
Source code in synt/stmt/fn.py
vararg
¤
|
Initialize a variable argument.
This is equivalent to FnArg(...).vararg()
.
Examples:
Source code in synt/stmt/fn.py
kwarg
¤
|
Initialize a keyword argument.
This is equivalent to FnArg(...).kwarg()
.
Examples:
Source code in synt/stmt/fn.py
def_
¤
|
Initialize a function definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Function name. |
required |
async_def
¤
|
Initialize an async function definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Function name. |
required |
importing
¤
Import
¤
Bases: Statement
The import
statement.
Examples:
References
Source code in synt/stmt/importing.py
__init__
¤
Initialize a new import
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
ImportType
|
Identifiers that are imported. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If no import names are provided. |
Source code in synt/stmt/importing.py
indented
¤
Source code in synt/stmt/importing.py
ImportFrom
¤
Bases: Statement
The from ... import
statement.
Examples:
References
Source code in synt/stmt/importing.py
__init__
¤
Initialize a new from ... import
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
ModPath
|
The module to import from. |
required |
names |
ImportType
|
Identifiers that are imported. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If no import names are provided. |
Source code in synt/stmt/importing.py
indented
¤
Source code in synt/stmt/importing.py
ImportFromBuilder
¤
The builder for ImportFrom
.
Source code in synt/stmt/importing.py
__init__
¤
|
Initialize a new from ... import
statement builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
ModPath | Identifier
|
The module to import from. |
required |
Source code in synt/stmt/importing.py
import_
¤
|
Import target objects from the module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
ImportType
|
Items that are imported. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If no import names are provided. |
Source code in synt/stmt/importing.py
keyword
¤
KeywordStatement
¤
Bases: Statement
A statement that only contains a specific keyword.
Examples:
Source code in synt/stmt/keyword.py
loop
¤
ForLoop
¤
Bases: Statement
The for
loop.
Examples:
References
For
.
Source code in synt/stmt/loop.py
target
instance-attribute
¤
|
Target item for the iteration.
Notes
Tuples will be automatically unwrapped.
orelse
instance-attribute
¤
The body of the fallback block, aka for ... else
.
__init__
¤
|
Initialize the loop.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
Target item for the iteration. |
required |
it |
IntoExpression
|
The expression to iterate over. |
required |
body |
Block
|
The body of the loop. |
required |
Source code in synt/stmt/loop.py
else_
¤
Set the fallback else
block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
The body of the fallback block. |
()
|
indented
¤
Source code in synt/stmt/loop.py
ForLoopBuilder
¤
Builder for for
loop.
References
Source code in synt/stmt/loop.py
__init__
¤
|
Initialize a new for
loop builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
Target item for the iteration. |
required |
in_
¤
|
Set the iterator of the loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
it |
IntoExpression
|
The expression to iterate over. |
required |
block
¤
Set the block of the loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*statements |
Statement
|
Statements to include in the loop body. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If the required fields ( |
Source code in synt/stmt/loop.py
WhileLoop
¤
The while
loop.
References
Source code in synt/stmt/loop.py
orelse
instance-attribute
¤
The body of the fallback block, aka while ... else
.
__init__
¤
|
Initialize a new while
loop.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
The condition. |
required |
body |
Block
|
The body of the loop. |
required |
Source code in synt/stmt/loop.py
else_
¤
Set the fallback else
block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
The body of the fallback block. |
()
|
indented
¤
Source code in synt/stmt/loop.py
WhileLoopBuilder
¤
Builder for while
loop.
Examples:
References
Source code in synt/stmt/loop.py
__init__
¤
|
Initialize a new while
loop builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
The condition. |
required |
match_case
¤
MatchCase
¤
Bases: Statement
A case
statement.
References
Source code in synt/stmt/match_case.py
guard
instance-attribute
¤
|
Pattern guard.
__init__
¤
|
Initialize a case
statement.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
IntoExpression
|
Match pattern. |
required |
guard |
IntoExpression | None
|
Pattern guard. |
required |
body |
Block
|
Case body. |
required |
Source code in synt/stmt/match_case.py
indented
¤
Source code in synt/stmt/match_case.py
MatchCaseBuilder
¤
Builder for MatchCase
.
Source code in synt/stmt/match_case.py
__init__
¤
|
Initialize a new builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
IntoExpression
|
Match pattern. |
required |
if_
¤
|
Set the guard.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
guard |
IntoExpression
|
Pattern guard. |
required |
Match
¤
Bases: Statement
The match
statement.
Examples:
Notes
Python views [x]
, (x)
, etc, as different case
nodes,
but Synt views them as the same.
Synt accepts any form of expression as case patterns,
and you must check yourself.
References
Source code in synt/stmt/match_case.py
__init__
¤
|
Initialize a new match
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
IntoExpression
|
Match subject. |
required |
case_
¤
|
Append a new case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
IntoExpression
|
Match pattern. |
required |
indented
¤
Source code in synt/stmt/match_case.py
namespace
¤
Global
¤
Bases: Statement
The global
statement.
Examples:
References
Source code in synt/stmt/namespace.py
__init__
¤
|
Initialize a new global
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier
|
Global variable names. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If the |
Source code in synt/stmt/namespace.py
Nonlocal
¤
Bases: Statement
The nonlocal
statement.
Examples:
References
Source code in synt/stmt/namespace.py
__init__
¤
|
Initialize a new nonlocal
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier
|
Nonlocal variable names. |
()
|
Raises:
Type | Description |
---|---|
ValueError
|
If the |
Source code in synt/stmt/namespace.py
raising
¤
Raise
¤
Bases: Statement
The raise
statement.
Examples:
References
Source code in synt/stmt/raising.py
__init__
¤
|
Initialize a new raise
statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception |
IntoExpression | None
|
The exception to raise. |
None
|
Source code in synt/stmt/raising.py
from_
¤
|
Set the cause of the raised exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cause |
IntoExpression
|
The origin of the raised exception. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in synt/stmt/raising.py
indented
¤
Source code in synt/stmt/raising.py
returns
¤
Return
¤
Bases: Statement
The return
statement.
Examples:
References
Source code in synt/stmt/returns.py
expression
instance-attribute
¤
|
The value to return from the function.
__init__
¤
|
Initialize the return statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression |
IntoExpression | None
|
The value to return from the function. |
None
|
Source code in synt/stmt/returns.py
indented
¤
stmt
¤
IntoStatement
¤
Any type that can be converted into a statement.
Source code in synt/stmt/stmt.py
Statement
¤
Bases: IntoCode
, IntoStatement
A base class for any Python statement.
Source code in synt/stmt/stmt.py
into_statement
¤
indented
abstractmethod
¤
Return the code block with appropriate indentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent_width |
int
|
number of |
required |
indent_atom |
str
|
string to use for indentation. E.g. |
required |
Returns:
Type | Description |
---|---|
str
|
indented code block. |
Source code in synt/stmt/stmt.py
try_catch
¤
ExceptionHandler
¤
Bases: Statement
Exception handler.
References
Source code in synt/stmt/try_catch.py
is_group
instance-attribute
¤
Whether the exception handler is a group handler.
__init__
¤
|
Initialize a new exception handler.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression | None
|
The type of exception to catch. |
required |
is_group |
bool
|
Whether the exception handler is a group handler, aka |
required |
asname |
Identifier | None
|
The alias name. |
required |
body |
Block
|
The handler body. |
required |
Source code in synt/stmt/try_catch.py
indented
¤
Source code in synt/stmt/try_catch.py
ExceptionHandlerBuilder
¤
The builder for exception handlers.
References
Source code in synt/stmt/try_catch.py
is_group
instance-attribute
¤
Whether the exception handler is a group handler, aka except*
.
__init__
¤
Initialize a new exception handler builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression | None
|
The type of exception to catch. |
required |
is_group |
bool
|
Whether the exception handler is a group handler, aka |
required |
parent |
Try
|
Parent node. |
required |
Source code in synt/stmt/try_catch.py
as_
¤
|
Try
¤
Bases: Statement
The try
statement.
Notes
Python views except
and except*
as separate statement types,
but Synt does view them as the same kind and a pair of different variations.
That means if you write except
and except*
statements together in a single Try
,
Synt won't complain about it, but the Python parser will reject it.
Examples:
Source code in synt/stmt/try_catch.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
__init__
¤
|
Initialize a new try
statement.
DO NOT USE THIS IN YOUR CODE!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
try_block |
Block
|
The block to catch exceptions. |
required |
handlers |
list[ExceptionHandler]
|
Exception handlers. |
required |
orelse |
Block | None
|
Fallback handler, aka |
required |
final |
Block | None
|
Final workaround body, aka |
required |
Source code in synt/stmt/try_catch.py
except_
¤
|
Append a new exception handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression | None
|
The type of exception to catch. |
None
|
except_star
¤
|
Append a new group exception handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression | None
|
The type of exception to catch. |
required |
else_
¤
Set the fallback handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
The statements in the fallback handler. |
()
|
finally_
¤
Set the final workaround body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
The statements in the final workaround body. |
()
|