synt.expr.comprehension
¤
Comprehension
¤
Bases: IntoExpression
, IntoCode
A Comprehension expression.
Attribute explanation:
Note:
Comprehension
is not a subclass of expr
.Expression.
However, it implements expr
.IntoExpression,
and will be internally converted into GeneratorComprehension
.
References
Source code in synt/expr/comprehension.py
elt
instance-attribute
¤
|
The expression to evaluate when iterating over the
iterator
.
Note: aka "extract, load, transform".
comprehensions
instance-attribute
¤
|
Generator nodes.
__init__
¤
|
Initialize a new comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elt |
IntoExpression
|
The expression to evaluate. |
required |
comprehensions |
list[ComprehensionNode]
|
The generator nodes. |
required |
Source code in synt/expr/comprehension.py
into_expression
¤
|
ComprehensionNode
¤
Bases: IntoCode
Source code in synt/expr/comprehension.py
target
instance-attribute
¤
|
Comprehension for
-loop target identifiers.
iterator
instance-attribute
¤
|
The iterator to iterate over.
ifs
instance-attribute
¤
|
A list of if
expressions to filter comprehension result.
__init__
¤
|
Initialize a new comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
list[Identifier]
|
The target identifiers. |
required |
iterator |
IntoExpression
|
The iterator to iterate over. |
required |
ifs |
list[IntoExpression]
|
A list of |
required |
is_async |
bool
|
Whether the iterator is asynchronous. |
required |
Source code in synt/expr/comprehension.py
into_code
¤
Source code in synt/expr/comprehension.py
GeneratorComprehension
¤
Bases: Expression
A generator comprehension expression.
Note:
GeneratorComprehension
is a subclass of expr
.Expression,
working as a wrapper for Comprehension
.
Source code in synt/expr/comprehension.py
comprehension
instance-attribute
¤
|
The inner comprehension expression.
__init__
¤
|
Initialize a generator comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comprehension |
Comprehension
|
The inner comprehension expression to wrap. |
required |
ComprehensionBuilder
¤
Bases: IntoExpression
Builder for Comprehension
.
Source code in synt/expr/comprehension.py
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 |
|
__init__
¤
|
Initialize a generator comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elt |
IntoExpression
|
The expression to evaluate. |
required |
target |
list[Identifier]
|
The target of the iteration. |
required |
is_async |
bool
|
Whether the comprehension is asynchronous. |
False
|
Source code in synt/expr/comprehension.py
init
staticmethod
¤
|
Initialize a generator comprehension expression and return the first node builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elt |
IntoExpression
|
The expression to evaluate. |
required |
target |
list[Identifier]
|
The target of the iteration. |
required |
is_async |
bool
|
Whether the comprehension is asynchronous. |
False
|
Source code in synt/expr/comprehension.py
curr_node
¤
|
for_
¤
|
Create a new comprehension node.
This will finish the previous ComprehensionNodeBuilder
and start a new one.
Source code in synt/expr/comprehension.py
async_for
¤
|
Create a new async comprehension node.
This will finish the previous ComprehensionNodeBuilder
and start a new one.
Source code in synt/expr/comprehension.py
build
¤
|
Build the comprehension expression.
Raises:
Type | Description |
---|---|
ValueError
|
If any required fields are missing. |
into_expression
¤
|
ComprehensionNodeBuilder
¤
Bases: IntoExpression
Builder for ComprehensionNode
.
Source code in synt/expr/comprehension.py
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 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 |
|
__init__
¤
|
Initialize an empty builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
ComprehensionBuilder
|
The root builder. |
required |
is_async |
bool
|
Whether the comprehension is asynchronous. |
False
|
Source code in synt/expr/comprehension.py
target
¤
|
Set the target of the comprehension generator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Identifier
|
The target identifiers. |
()
|
in_
¤
|
iterator
¤
|
Set the iterator of the comprehension generator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterator |
IntoExpression
|
The iterator to iterate over. |
required |
if_
¤
|
Add an if
expression to filter comprehension result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
if_expr |
IntoExpression
|
The |
required |
async_
¤
sync
¤
build
¤
|
Build the comprehension node.
Raises:
Type | Description |
---|---|
ValueError
|
If any required fields are missing. |
Source code in synt/expr/comprehension.py
for_
¤
|
Create a new comprehension node.
This will call root's for_
.
async_for
¤
|
Create a new async comprehension node.
This will call root's async_for
.
Source code in synt/expr/comprehension.py
build_comp
¤
|
Build the comprehension expression.
Raises:
Type | Description |
---|---|
ValueError
|
If any required fields are missing. |
into_expression
¤
|