| 1 |
[case testTemplateStringBasics] |
| 2 |
reveal_type(t"foobar") # N: Revealed type is "string.templatelib.Template" |
| 3 |
t"{'foobar'}" |
| 4 |
t"foo{'bar'}" |
| 5 |
t".{1}." |
| 6 |
t"{type(1)}" |
| 7 |
t"{1!r}" |
| 8 |
t"{1:03d}" |
| 9 |
t"{1!r:03d}" |
| 10 |
|
| 11 |
from string.templatelib import Template |
| 12 |
a: Template |
| 13 |
a = t"foobar" |
| 14 |
a = t"{'foobar'}" |
| 15 |
[builtins fixtures/f_string.pyi] |
| 16 |
|
| 17 |
[case testTemplateStringWithoutExplicitImport] |
| 18 |
reveal_type(t"implicit import works") # N: Revealed type is "string.templatelib.Template" |
| 19 |
[builtins fixtures/f_string.pyi] |
| 20 |
|
| 21 |
[case testTemplateStringExpressionsOk] |
| 22 |
t".{1 + 1}." |
| 23 |
t".{1 + 1}.{'foo' + 'bar'}" |
| 24 |
[builtins fixtures/f_string.pyi] |
| 25 |
|
| 26 |
[case testTemplateStringExpressionsErrors] |
| 27 |
t"{1 + ''}" # E: Unsupported operand types for + ("int" and "str") |
| 28 |
t".{1 + ''}" # E: Unsupported operand types for + ("int" and "str") |
| 29 |
[builtins fixtures/f_string.pyi] |
| 30 |
|
| 31 |
[case testTemplateStringParseFormatOptions] |
| 32 |
value = 10.5142 |
| 33 |
width = 10 |
| 34 |
precision = 4 |
| 35 |
t"result: {value:{width}.{precision}}" |
| 36 |
[builtins fixtures/f_string.pyi] |
| 37 |
|
| 38 |
[case testTemplateStringNestedExpressionsTypeChecked] |
| 39 |
t"{2:{3 + ''}}" # E: Unsupported operand types for + ("int" and "str") |
| 40 |
[builtins fixtures/f_string.pyi] |
| 41 |
|
| 42 |
[case testIncrementalTemplateStringImplicitDependency] |
| 43 |
import m |
| 44 |
reveal_type(m.x) |
| 45 |
[file m.py] |
| 46 |
x = "foo" |
| 47 |
[file m.py.2] |
| 48 |
x = t"foo" |
| 49 |
[out1] |
| 50 |
main:2: note: Revealed type is "builtins.str" |
| 51 |
[out2] |
| 52 |
main:2: note: Revealed type is "string.templatelib.Template" |
| 53 |
[builtins fixtures/f_string.pyi] |