Format expression type checker. This file is conceptually part of ExpressionChecker and TypeChecker. Main functionality is located in StringFormatterChecker.check_str_format_call() for '{}'.format(), and in StringFormatterChecker.check_str_interpolation() for printf-style % interpolation. Note that although at runtime format strings are parsed using custom parsers, here we use a regexp-based approach. This way we 99% match runtime behaviour while keeping implementation simple.
Class |
|
Undocumented |
Class |
|
String interpolation/formatter type checker. |
Function | compile |
Construct regexp to match format conversion specifiers in % interpolation. |
Function | compile |
Construct regexps to match format conversion specifiers in str.format() calls. |
Function | find |
Return list of raw (un-parsed) format specifiers in format string. |
Function | has |
Is this a specific instance type, or a union that contains it? |
Function | parse |
Parse c-printf-style format string into list of conversion specifiers. |
Function | parse |
Parse format string into list of conversion specifiers. |
Constant | DUMMY |
Undocumented |
Constant | FLOAT |
Undocumented |
Constant | FORMAT |
Undocumented |
Constant | FORMAT |
Undocumented |
Constant | FORMAT |
Undocumented |
Constant | NUMERIC |
Undocumented |
Constant | NUMERIC |
Undocumented |
Constant | REQUIRE |
Undocumented |
Constant | REQUIRE |
Undocumented |
Type Alias |
|
Undocumented |
Type Alias |
|
Undocumented |
Type Alias |
|
Undocumented |
Construct regexp to match format conversion specifiers in % interpolation. See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting The regexp is intentionally a bit wider to report better errors.
Construct regexps to match format conversion specifiers in str.format() calls. See After https://docs.python.org/3/library/string.html#formatspec for specifications. The regexps are intentionally wider, to report better errors, instead of just not matching.
str
, ctx: Context
, msg: MessageBuilder
) -> list[ tuple[ str, int]]|None
:
(source)
¶
Return list of raw (un-parsed) format specifiers in format string. Format specifiers don't include enclosing braces. We don't use regexp for this because they don't work well with nested/repeated patterns (both greedy and non-greedy), and these are heavily used internally for representation of f-strings. Return None in case of an error.
Is this a specific instance type, or a union that contains it? We use this ad-hoc function instead of a proper visitor or subtype check because some str vs bytes errors are strictly speaking not runtime errors, but rather highly counter-intuitive behavior. This is similar to what is used for --strict-equality.
str
, ctx: Context
, msg: MessageBuilder
, nested: bool
= False) -> list[ ConversionSpecifier]|None
:
(source)
¶
Parse format string into list of conversion specifiers. The specifiers may be nested (two levels maximum), in this case they are ordered as '{0:{1}}, {2:{3}{4}}'. Return None in case of an error.