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