Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse each format-string component separately (#3390)
Fixes #3385. The old code evaluated each FormattedValue as an expression potentially returning the type of the value, rather than a string. But that's wrong, because a FormattedValue can exist on its own when it's not being joined to any other format strings. The new code evaluates each FormattedValue by synthesizing '{}'.format(expr) and then, if necessary, joins them in JoinedStr using ''.join(items).
- Loading branch information
1 parent
35fbfb6
commit d4864a9
Showing
3 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Builtins stub used for format-string-related test cases. | ||
# We need str and list, and str needs join and format methods. | ||
|
||
from typing import TypeVar, Generic, Iterable, Iterator, List, overload | ||
|
||
T = TypeVar('T') | ||
|
||
class object: | ||
def __init__(self): pass | ||
|
||
class type: | ||
def __init__(self, x) -> None: pass | ||
|
||
class ellipsis: pass | ||
|
||
class list(Iterable[T], Generic[T]): | ||
@overload | ||
def __init__(self) -> None: pass | ||
@overload | ||
def __init__(self, x: Iterable[T]) -> None: pass | ||
def append(self, x: T) -> None: pass | ||
|
||
class tuple(Generic[T]): pass | ||
|
||
class function: pass | ||
class int: | ||
def __add__(self, i: int) -> int: pass | ||
|
||
class float: pass | ||
class bool(int): pass | ||
|
||
class str: | ||
def __add__(self, s: str) -> str: pass | ||
def format(self, *args) -> str: pass | ||
def join(self, l: List[str]) -> str: pass | ||
|