synt.stmt.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 |