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 |
file
¤
File
¤
Abstract file containing arbitrary python code.
Examples:
Source code in synt/file.py
__init__
¤
Initialize a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
Statements to include in the file. |
()
|
into_str
¤
Convert the file into a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent_width |
int
|
number of |
0
|
indent_atom |
str
|
string to use for indentation. E.g. |
' '
|
Source code in synt/file.py
prelude
¤
Synt Prelude¤
This module contains multiple utilities that is often used when working with Synt.
It's suggested to import everything from this module instead of writing several separate import statements.
dict_
module-attribute
¤
|
Alias DictVerbatim
.
Notes
dict
is a built-in type in Python, so it's renamed to dict_
with a suffix.
list_
module-attribute
¤
|
Alias ListVerbatim
.
Notes
list
is a built-in type in Python, so it's renamed to list_
with a suffix.
set_
module-attribute
¤
|
Alias SetVerbatim
.
Notes
set
is a built-in type in Python, so it's renamed to set_
with a suffix.
slice_
module-attribute
¤
Alias Slice
.
Notes
slice
is a built-in type in Python, so it's renamed to slice_
with a suffix.
id_
module-attribute
¤
|
Alias Identifier
.
Notes
id
is a built-in function in Python, so it's renamed to id_
with a suffix.
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 |
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.
File
¤
Abstract file containing arbitrary python code.
Examples:
Source code in synt/file.py
__init__
¤
Initialize a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
Statement
|
Statements to include in the file. |
()
|
into_str
¤
Convert the file into a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent_width |
int
|
number of |
0
|
indent_atom |
str
|
string to use for indentation. E.g. |
' '
|
Source code in synt/file.py
Block
¤
Bases: Statement
A Python code block.
Source code in synt/stmt/block.py
__init__
¤
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
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
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
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
if_
¤
|
Initialize a new branch statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test |
IntoExpression
|
The expression to test. |
required |
References
class_
¤
|
Initialize a class without decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Class name. |
required |
async_def
¤
|
Initialize an async function definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Function name. |
required |
def_
¤
|
Initialize a function definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
Function name. |
required |
kwarg
¤
|
Initialize a keyword argument.
This is equivalent to FnArg(...).kwarg()
.
Examples:
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
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. |
()
|
indented
¤
Source code in synt/stmt/try_catch.py
tokens
¤
ident
¤
id_
module-attribute
¤
|
Alias Identifier
.
Notes
id
is a built-in function in Python, so it's renamed to id_
with a suffix.
Identifier
¤
Bases: IntoExpression
, IntoCode
Represents a valid Python identifier.
For more information, see the Identifier and Keywords section of the Python's standard documentation.
Source code in synt/tokens/ident.py
__init__
¤
Initialize a new identifier.
The raw content will be checked immediately when initializing the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw |
str
|
Raw identifier text. |
required |
Raises:
Type | Description |
---|---|
InvalidIdentifierException
|
If the raw identifier text is not a valid identifier. |
Examples:
Source code in synt/tokens/ident.py
into_expression
¤
|
expr
¤
|
Initialize a new expression with self
.
Alias for into_expression
.
Examples:
Source code in synt/tokens/ident.py
into_code
¤
as_
¤
|
Construct a new alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alias |
Identifier
|
The alias name. |
required |
IdentifierExpr
¤
Bases: Expression
An identifier as a Python expression.
See Identifier
for more information.
Source code in synt/tokens/ident.py
__init__
¤
|
Initialize a new identifier.
Use Identifier
instead and converts it into an expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw |
Identifier
|
Identifier to be used as an expression. |
required |
Source code in synt/tokens/ident.py
from_str
staticmethod
¤
|
Parse an identifier from a string.
The raw content will be checked immediately when initializing the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
Raw identifier text. |
required |
Raises:
Type | Description |
---|---|
InvalidIdentifierException
|
If the raw identifier text is not a valid identifier. |
Source code in synt/tokens/ident.py
keywords
¤
hard_keywords
module-attribute
¤
All Python's hard keywords, in string format.
Alias for std library's keyword.kwlist
.
soft_keywords
module-attribute
¤
|
All Python's soft keywords, in string format.
Alias for std library's keyword.softkwlist
.
is_hard_keyword
¤
Check if a string is a hard keyword.
See hard_keywords
for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i |
str
|
The string to check. |
required |
is_soft_keyword
¤
Check if a string is a soft keyword.
See soft_keywords
for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i |
str
|
The string to check. |
required |
kv_pair
¤
KVPair
¤
Bases: Expression
A key-value pair, aka a: b
.
This is mainly used in dict initializing ({a: b}
).
Source code in synt/tokens/kv_pair.py
__init__
¤
|
Initialize a key-value pair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
IntoExpression
|
Key expression. |
required |
value |
IntoExpression
|
Value expression. |
required |
Examples:
Source code in synt/tokens/kv_pair.py
lit
¤
Literal
¤
Bases: Expression
Literal Python expression.
Source code in synt/tokens/lit.py
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 |
|
__init__
¤
Initialize a Literal value.
DO NOT USE THIS IN YOUR CODE! Use other entry points instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src |
str
|
Source code of the literal. |
required |
bool_
staticmethod
¤
Initialize a literal boolean.
Notes
bool
is a built-in type, so this function is suffixed with a _
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
bool
|
Original boolean. |
required |
Examples:
Source code in synt/tokens/lit.py
str_
staticmethod
¤
Initialize a literal string.
Notes
str
is a built-in type, so this function is suffixed with a _
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
Original string. |
required |
Examples:
Source code in synt/tokens/lit.py
int_
staticmethod
¤
Initialize a literal integer.
Notes
int
is a built-in type, so this function is suffixed with a _
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
int
|
Original integer. |
required |
Examples:
Source code in synt/tokens/lit.py
ty
¤
type_param
¤
TypeVar
¤
Bases: IntoCode
TypeVar
in type parameters.
Examples:
References
Source code in synt/ty/type_param.py
__init__
¤
|
Initialize a type variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the type variable. |
required |
bound |
IntoExpression | None
|
The bound of the type variable. |
None
|
Source code in synt/ty/type_param.py
TypeVarTuple
¤
Bases: IntoCode
Type variable tuple.
Examples:
References
Source code in synt/ty/type_param.py
__init__
¤
|
Initialize a type variable tuple.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the type variable tuple. |
required |
TypeParamSpec
¤
Bases: IntoCode
Type parameter spec.
Examples:
References
Source code in synt/ty/type_param.py
__init__
¤
|
Initialize a type parameter spec.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Identifier
|
The name of the type parameter spec. |
required |