synt.expr
¤
alias
¤
Alias
¤
Bases: Expression
Import alias.
Examples:
References
Source code in synt/expr/alias.py
__init__
¤
|
Initialize a new alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier | ModPath | Expression
|
The names of the alias item. |
required |
asname |
Identifier
|
The alias name. |
required |
Source code in synt/expr/alias.py
attribute
¤
Attribute
¤
Bases: Expression
The operation to get a value's attribute.
References
Source code in synt/expr/attribute.py
__init__
¤
|
Initialize an attribute expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
The target of the operation. |
required |
attr |
str
|
The attribute's name. |
required |
Source code in synt/expr/attribute.py
binary_op
¤
BinaryOpType
¤
Bases: IntEnum
Binary operator type.
Exception:
Although NamedExpr
takes the form of a binary operator, it is not a binary operator (at least not in synt
).
References
expr
.ExprPrecedence
Source code in synt/expr/binary_op.py
20 21 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 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 |
|
to_precedence
¤
|
Get the operator's backend expression's precedence.
Source code in synt/expr/binary_op.py
into_code
¤
Raises:
Type | Description |
---|---|
ValueError
|
If the provided operator type is not recognized. |
Source code in synt/expr/binary_op.py
BinaryOp
¤
Bases: Expression
Binary operation.
Source code in synt/expr/binary_op.py
__init__
¤
|
Initialize a binary operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op |
BinaryOpType
|
Binary operator type. |
required |
left |
IntoExpression
|
Left operand. |
required |
right |
IntoExpression
|
Right operand. |
required |
Source code in synt/expr/binary_op.py
call
¤
Call
¤
Bases: Expression
Calling a value.
References
Call.
Source code in synt/expr/call.py
args
instance-attribute
¤
|
Positional arguments of the call.
__init__
¤
|
Initialize a new Call
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
Call target. |
required |
args |
list[IntoExpression]
|
Positional arguments of the call. |
required |
keywords |
list[Keyword]
|
Keyword arguments of the call. |
required |
Source code in synt/expr/call.py
into_code
¤
Source code in synt/expr/call.py
Keyword
¤
Bases: IntoCode
Keyword arguments of a object call.
References
Source code in synt/expr/call.py
__init__
¤
|
Initialize a new keyword argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
Identifier
|
Keyword. |
required |
value |
IntoExpression
|
Value for the argument. |
required |
closure
¤
Closure
¤
Bases: Expression
, IntoCode
Python's closure expression, aka lambda
.
Notes
In Python, a lambda expression can have a single expression as its body. Synt won't try to create a separate function containing multiple statements, you must do it yourself.
References
Source code in synt/expr/closure.py
__init__
¤
|
Initialize a closure expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
list[Identifier]
|
Argument list. |
required |
body |
IntoExpression
|
expr.Expression body. |
required |
Source code in synt/expr/closure.py
ClosureBuilder
¤
Builder for Closure
.
Examples:
Source code in synt/expr/closure.py
__init__
¤
|
Initialize a closure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Identifier
|
Initial closure argument list. |
()
|
join
¤
|
Append new arguments to the closure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Identifier
|
New closure arguments. |
()
|
ret
¤
|
Set the expression to be returned by the closure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
e |
IntoExpression
|
expr.Expression to be returned. |
required |
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
¤
|
condition
¤
Condition
¤
Bases: Expression
Conditional expression, aka if - else
.
References
Source code in synt/expr/condition.py
true_expr
instance-attribute
¤
|
expr.Expression to evaluate and return if the condition is true.
false_expr
instance-attribute
¤
|
expr.Expression to evaluate and return if the condition is false.
__init__
¤
|
Initialize a new conditional expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition |
IntoExpression
|
Condition expression. |
required |
true_expr |
IntoExpression
|
expr.Expression to evaluate and return if the condition is true. |
required |
false_expr |
IntoExpression
|
expr.Expression to evaluate and return if the condition is false. |
required |
Source code in synt/expr/condition.py
ConditionBuilder
¤
Builder for Condition
.
Source code in synt/expr/condition.py
__init__
¤
|
Initialize an empty condition builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition |
IntoExpression
|
Condition expression. |
required |
true_expr |
IntoExpression
|
expr.Expression to evaluate if the condition is true. |
required |
Source code in synt/expr/condition.py
false_expr
¤
|
Set the expression to evaluate if the condition is false.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
e |
IntoExpression
|
expr.Expression to evaluate. |
required |
build
¤
Build the condition.
Raises:
Type | Description |
---|---|
ValueError
|
If any of the required field is empty. |
Source code in synt/expr/condition.py
else_
¤
|
Set the false_expr
and build the builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
IntoExpression
|
expr.Expression to evaluate if the condition is false. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the required field is empty. |
Source code in synt/expr/condition.py
dict
¤
dict_
module-attribute
¤
|
Alias DictVerbatim
.
Notes
dict
is a built-in type in Python, so it's renamed to dict_
with a suffix.
DictDisplay
¤
DictVerbatim
¤
Bases: DictDisplay
Verbatim dict expression.
Examples:
Source code in synt/expr/dict.py
DictComprehension
¤
Bases: DictDisplay
Dict comprehension expression.
Note that you can also directly insert a comprehension expression into a normal dictionary, but that will become a generator comprehension and returns a pair of extra parenthesis.
Examples:
References
Source code in synt/expr/dict.py
comprehension
instance-attribute
¤
|
Internal comprehension expression.
__init__
¤
|
Initialize a new dict comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comprehension |
Comprehension | ComprehensionBuilder | ComprehensionNodeBuilder
|
Internal comprehension expression. |
required |
Raises:
Type | Description |
---|---|
ExpressionTypeException
|
Invalid dict comprehension result type,
typically not a |
Source code in synt/expr/dict.py
empty
¤
Empty
¤
expr
¤
ExprPrecedence
¤
Bases: IntEnum
Python's expression precedence.
Sort sequence: smaller = prior
References
Source code in synt/expr/expr.py
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 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 |
|
Atom
class-attribute
instance-attribute
¤
Atom expression: Binding or parenthesized expression, list display, dictionary display, set display, and other bound operations.
Examples:
Call
class-attribute
instance-attribute
¤
Exponential
class-attribute
instance-attribute
¤
Exponential operation: exponentiation.
Exception:
The power operator **
binds less tightly than an arithmetic or bitwise unary operator on its right,
that is, 2 ** -1
is 0.5
.
Examples:
Unary
class-attribute
instance-attribute
¤
Multiplicative
class-attribute
instance-attribute
¤
Multiplicative operation: multiplication, matrix multiplication, division, floor division, remainder.
Notes
The %
operator is also used for string formatting; the same precedence applies.
Examples:
Additive
class-attribute
instance-attribute
¤
Shift
class-attribute
instance-attribute
¤
Comparative
class-attribute
instance-attribute
¤
BoolNot
class-attribute
instance-attribute
¤
BoolAnd
class-attribute
instance-attribute
¤
Conditional
class-attribute
instance-attribute
¤
Lambda
class-attribute
instance-attribute
¤
ExprType
¤
Bases: IntEnum
Expression type in Synt.
Source code in synt/expr/expr.py
IntoExpression
¤
Bases: IntoCode
Abstract class for those that can be converted into an
Expression
.
Source code in synt/expr/expr.py
into_expression
abstractmethod
¤
|
expr
¤
|
Convert the object into an expression.
This is a convenience method that calls into_expression()
and returns the result.
into_code
¤
Convert the object into a code string.
This is a convenience method that calls into_expression()
and calls into_code
on the result.
Expression
¤
Bases: IntoExpression
, IntoCode
Base class for any expression in Python.
Source code in synt/expr/expr.py
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 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
|
into_code
abstractmethod
¤
into_expression
¤
|
ensure_identifier
¤
|
Ensure that the expression is an identifier and returns it.
Raises:
Type | Description |
---|---|
ValueError
|
If the expression is not an identifier. |
Source code in synt/expr/expr.py
add
¤
|
Add operation.
Examples:
Source code in synt/expr/expr.py
sub
¤
|
Subtract operation.
Examples:
Source code in synt/expr/expr.py
mul
¤
|
Multiply operation.
Examples:
Source code in synt/expr/expr.py
div
¤
|
Divide operation.
Examples:
Source code in synt/expr/expr.py
truediv
¤
|
floor_div
¤
|
Floor divide operation.
Examples:
Source code in synt/expr/expr.py
mod
¤
|
Modulus operation.
Examples:
Source code in synt/expr/expr.py
pow
¤
|
Exponentiation operation.
Examples:
Source code in synt/expr/expr.py
at
¤
|
At(matrix multiplication) operation.
Examples:
Source code in synt/expr/expr.py
matmul
¤
|
lshift
¤
|
Left shift operation.
Examples:
Source code in synt/expr/expr.py
rshift
¤
|
Right shift operation.
Examples:
Source code in synt/expr/expr.py
lt
¤
|
Less than operation.
Examples:
Source code in synt/expr/expr.py
le
¤
|
Less than or equal to operation.
Examples:
Source code in synt/expr/expr.py
gt
¤
|
Greater than operation.
Examples:
Source code in synt/expr/expr.py
ge
¤
|
Greater than or equal to operation.
Examples:
Source code in synt/expr/expr.py
eq
¤
|
Equal to operation.
Examples:
Source code in synt/expr/expr.py
ne
¤
|
Not equal to operation.
Examples:
Source code in synt/expr/expr.py
in_
¤
|
Membership test operation.
Examples:
Source code in synt/expr/expr.py
not_in
¤
|
Negative membership test operation.
Examples:
Source code in synt/expr/expr.py
is_
¤
|
Identity test operation.
Examples:
Source code in synt/expr/expr.py
is_not
¤
|
Negative identity test operation.
Examples:
Source code in synt/expr/expr.py
bool_and
¤
|
Boolean AND operation.
Examples:
Source code in synt/expr/expr.py
bool_or
¤
|
Boolean OR operation.
Examples:
Source code in synt/expr/expr.py
bit_and
¤
|
Bitwise AND operation.
Examples:
Source code in synt/expr/expr.py
bit_or
¤
|
Bitwise OR operation.
Examples:
Source code in synt/expr/expr.py
bit_xor
¤
|
Bitwise XOR operation.
Examples:
Source code in synt/expr/expr.py
__lt__
¤
|
__le__
¤
|
__gt__
¤
|
__ge__
¤
|
__eq__
¤
|
__ne__
¤
|
__lshift__
¤
|
__rshift__
¤
|
__and__
¤
|
__or__
¤
|
__xor__
¤
|
__add__
¤
|
__sub__
¤
|
__mul__
¤
|
__truediv__
¤
|
__floordiv__
¤
|
__mod__
¤
|
__matmul__
¤
|
positive
¤
negative
¤
neg
¤
not_
¤
bool_not
¤
invert
¤
bit_not
¤
await_
¤
awaited
¤
unpack
¤
starred
¤
unpack_seq
¤
double_starred
¤
unpack_dict
¤
yield_
¤
yield_from
¤
Yield from operation, alias yield_from
function.
__neg__
¤
__not__
¤
__invert__
¤
named
¤
|
Assign the expression to self
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr |
IntoExpression
|
The expression to assign. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Examples:
Source code in synt/expr/expr.py
named_as
¤
|
Assign self to the target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Identifier
|
The target identifier. |
required |
Examples:
Source code in synt/expr/expr.py
attr
¤
attribute.Attribute getting operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The attribute name. |
required |
Examples:
Source code in synt/expr/expr.py
call
¤
|
Calling a function or object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
IntoExpression | tuple[Identifier, IntoExpression]
|
Positional arguments. |
()
|
**kwargs |
IntoExpression
|
Keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If any argument is not |
Examples:
Source code in synt/expr/expr.py
for_
¤
|
Initialize a new comprehension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Identifier
|
The target of the iteration. |
()
|
Examples:
Source code in synt/expr/expr.py
async_for
¤
|
Initialize a new async comprehension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Identifier
|
The iterator expression of the comprehension. |
()
|
Examples:
Source code in synt/expr/expr.py
if_
¤
|
Initialize a new condition expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cond |
IntoExpression
|
The condition expression. |
required |
Examples:
Source code in synt/expr/expr.py
subscribe
¤
|
Subscribe to the expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slices |
Slice | IntoExpression
|
The slice expressions. |
()
|
Examples:
Source code in synt/expr/expr.py
__getitem__
¤
|
Alias subscribe
.
Source code in synt/expr/expr.py
wrap
¤
wrapped
¤
par
¤
atom
¤
assign
¤
|
Create a new assignment statement, take self
as the target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
IntoExpression
|
The value to assign. |
required |
assign_to
¤
|
Create a new assignment statement, take self
as the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
The value to be assigned. |
required |
Source code in synt/expr/expr.py
type
¤
|
Create a new typed assignment statement, take self
as the target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ty |
IntoExpression
|
The type of the target. |
required |
ty
¤
|
stmt
¤
as_
¤
|
Convert the expression into an alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Identifier
|
The target identifier. |
required |
fstring
¤
FormatString
¤
Bases: Expression
Format string, aka f-string.
Examples:
References
Source code in synt/expr/fstring.py
__init__
¤
|
Initialize a new format string expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes |
FormatNode | str
|
Formatting nodes. |
()
|
FormatConversionType
¤
Bases: IntEnum
Format conversion type.
References
Source code in synt/expr/fstring.py
from_str
staticmethod
¤
|
Parse a conversion string.
text | result |
---|---|
"" , "!" |
FormatConversionType.No |
"a" , "!a" |
FormatConversionType.Ascii |
"r" , "!r" |
FormatConversionType.Repr |
"s" , "!s" |
FormatConversionType.Str |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
Conversion string. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the conversion string is invalid (valid forms are the texts listed above). |
Source code in synt/expr/fstring.py
into_str
¤
Converts the conversion type into a string.
Raises ValueError: If the conversion type is not recognized.
Source code in synt/expr/fstring.py
FormatNode
¤
Bases: IntoCode
Format node used in FormatString
.
Examples:
Source code in synt/expr/fstring.py
value
instance-attribute
¤
|
expr.Expression to be joint with other nodes.
format_spec
instance-attribute
¤
|
The formatting of the value.
Notes
Different from Python's behavior, Synt directly use str
as the type of format_spec
,
instead of wrapping it in a JointStr(Constant(string))
.
conversion
instance-attribute
¤
|
The conversion of the expression, e.g. __str__
, __repr__
, ...
__init__
¤
|
Initialize a format node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
IntoExpression
|
expr.Expression to be joint with other nodes. |
required |
format_spec |
str | None
|
The formatting of the value. |
None
|
conversion |
FormatConversionType | str
|
The conversion of the expression. |
No
|
Source code in synt/expr/fstring.py
list
¤
list_
module-attribute
¤
|
Alias ListVerbatim
.
Notes
list
is a built-in type in Python, so it's renamed to list_
with a suffix.
ListDisplay
¤
ListVerbatim
¤
Bases: ListDisplay
Verbatim list expression, aka starred-list
.
Examples:
References
Source code in synt/expr/list.py
items
instance-attribute
¤
list items.
__init__
¤
|
Initialize a new verbatim list expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
IntoExpression
|
list items. |
()
|
ListComprehension
¤
Bases: ListDisplay
list comprehension expression.
Examples:
References
Source code in synt/expr/list.py
comprehension
instance-attribute
¤
|
Internal comprehension expression.
__init__
¤
|
Initialize a new list comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comprehension |
Comprehension | ComprehensionBuilder | ComprehensionNodeBuilder
|
Internal comprehension expression. |
required |
Raises:
Type | Description |
---|---|
ExpressionTypeException
|
Invalid list comprehension result type,
typically a |
Source code in synt/expr/list.py
modpath
¤
ModPath
¤
Bases: IntoCode
Module path.
Examples:
Source code in synt/expr/modpath.py
__init__
¤
|
Initialize a new module path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier
|
Names of the path. |
()
|
depth |
int
|
Relative depth of the path. |
0
|
dep
¤
Set the depth of the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depth |
int
|
New depth of the path. |
required |
into_code
¤
as_
¤
|
Alias the import path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asname |
Identifier
|
Name of the alias. |
required |
relpath
¤
|
Initialize a path relatively (depth = 1
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier
|
Names of the path. |
()
|
Examples:
Source code in synt/expr/modpath.py
parentpath
¤
|
Initialize a path from its parent (depth = 2
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Identifier
|
Names of the path. |
()
|
Examples:
Source code in synt/expr/modpath.py
named_expr
¤
NamedExpr
¤
Bases: Expression
Inline assignment expression, aka :=
.
References
Source code in synt/expr/named_expr.py
value
instance-attribute
¤
|
The value to be assigned to the receiver.
__init__
¤
|
Initialize a named expr expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
receiver |
Identifier
|
The identifier to be assigned. |
required |
value |
IntoExpression
|
The value to be assigned to the receiver. |
required |
Source code in synt/expr/named_expr.py
set
¤
set_
module-attribute
¤
|
Alias SetVerbatim
.
Notes
set
is a built-in type in Python, so it's renamed to set_
with a suffix.
SetDisplay
¤
SetVerbatim
¤
Bases: SetDisplay
Verbatim set expression.
Examples:
Source code in synt/expr/set.py
items
instance-attribute
¤
Set items.
__init__
¤
|
Initialize a new verbatim set expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
IntoExpression
|
Set items. |
()
|
SetComprehension
¤
Bases: SetDisplay
Set comprehension expression.
Examples:
References
Source code in synt/expr/set.py
comprehension
instance-attribute
¤
|
Internal comprehension expression.
__init__
¤
|
Initialize a new set comprehension expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comprehension |
Comprehension | ComprehensionBuilder | ComprehensionNodeBuilder
|
Internal comprehension expression. |
required |
Raises:
Type | Description |
---|---|
ExpressionTypeException
|
Invalid set comprehension result type,
typically a |
Source code in synt/expr/set.py
subscript
¤
slice_
module-attribute
¤
Alias Slice
.
Notes
slice
is a built-in type in Python, so it's renamed to slice_
with a suffix.
Subscript
¤
Bases: Expression
Subscript operation.
References
Source code in synt/expr/subscript.py
slices
instance-attribute
¤
|
Slices to index the target.
__init__
¤
|
Initialize a Subscript
operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
IntoExpression
|
Target of the operation. |
required |
slices |
list[Slice | IntoExpression]
|
Slices to index the target. |
required |
Source code in synt/expr/subscript.py
Slice
¤
Bases: IntoCode
Slice constructor.
Examples:
References
Source code in synt/expr/subscript.py
step
instance-attribute
¤
|
Step of the slice.
__init__
¤
|
Initialize the slice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower |
IntoExpression
|
Lower bound of the slice. |
required |
upper |
IntoExpression
|
Upper bound of the slice. |
required |
step |
IntoExpression | None
|
Step of the slice. |
None
|
Source code in synt/expr/subscript.py
tuple
¤
Tuple
¤
Bases: Expression
Tuple expression.
Examples:
Source code in synt/expr/tuple.py
items
instance-attribute
¤
Tuple items.
__init__
¤
|
Initialize a tuple expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
IntoExpression
|
Tuple items. |
()
|
into_code
¤
into_code_implicit
¤
Convert the tuple into a string representation implicitly, omitting the parentheses.
type_check
¤
is_into_expr
¤
|
is_ident
¤
|
unary_op
¤
UnaryOpType
¤
Bases: IntEnum
Unary operator type.
References
expr
.ExprPrecedence
Source code in synt/expr/unary_op.py
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 125 126 127 128 |
|
Await
class-attribute
instance-attribute
¤
Await expression operator await
.
Notes
await
is a Python hard keyword, but synt treats it as a unary operator.
Yield
class-attribute
instance-attribute
¤
Yield expression operator yield
.
Notes
yield
is a Python hard keyword, but synt treats it as a unary operator.
YieldFrom
class-attribute
instance-attribute
¤
Yield-from expression operator yield from
.
Notes
yield from
is a Python hard keyword group, but synt treats it as a single unary operator.
to_precedence
¤
|
Get the operator's backend expression's precedence.
Source code in synt/expr/unary_op.py
into_code
¤
Converts the operator into a string representation.
Raises:
Type | Description |
---|---|
ValueError
|
If the operator is not recognized. |
Source code in synt/expr/unary_op.py
UnaryOp
¤
Bases: Expression
Unary operation.
Source code in synt/expr/unary_op.py
__init__
¤
|
Initialize a unary operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op |
UnaryOpType
|
Unary operator type. |
required |
e |
IntoExpression
|
Internal expression. |
required |
Source code in synt/expr/unary_op.py
unpack
¤
|
Sequence unpacking operation.
Examples:
Source code in synt/expr/unary_op.py
unpack_kv
¤
|
K-V pair unpacking operation.
Examples:
Source code in synt/expr/unary_op.py
yield_from
¤
|
Yield from operation.
Examples:
Source code in synt/expr/unary_op.py
wrapped
¤
Wrapped
¤
Bases: Expression
A wrapped expression, aka ( expr )
, which is always an atomic expression.
Examples:
Notes
Most plain expressions have their own expression precedence, and will be wrapped automatically by Synt. However, for those atomic expressions, some of them does have different parser precedence which is hard to represent beforehand. Thus, you must explicitly wrap them manually.
Source code in synt/expr/wrapped.py
__init__
¤
|
Initialize a wrapped expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inner |
IntoExpression
|
Inner expression. |
required |