You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mypyc] Introduce FormatOp and add a tokenizer for .format() call (#10935)
This PR adds a tokenizer that convert a str.format() format string into literals
and specifiers. By doing so, the code structure of `translate_str_format` is
clearer.
This PR also introduces `FormatOp`. Compare to `ConversionSpecifier`,
`FormatOp` has fewer attributes and indicates compile time optimizations.
For example, to mark a conversion from any object to string,
`ConversionSpecifier` may have several representations, like '%s', '{}' or
'{:{}}'. However, there would only exist one corresponding `FormatOp`.
Currently `FormatOp` is just an Enum for convenience. We might add
several attributes later and upgrade it to a class if we need to support
more conversions.
To help for the future optimization, these parts of code are extracted
into new functions:
* `generate_format_ops` that shrink `ConversionSpecifier` into `FormatOp`
* `convert_expr` that can help convert the expressions into desired results.
0 commit comments