@@ -794,6 +794,8 @@ def _validate_msg(line: Line, string_idx: int) -> TResult[None]:
794794 - The set of all string prefixes in the string group is of
795795 length greater than one and is not equal to {"", "f"}.
796796 - The string group consists of raw strings.
797+ - The string group would merge f-strings with different quote types
798+ and internal quotes.
797799 - The string group is stringified type annotations. We don't want to
798800 process stringified type annotations since pyright doesn't support
799801 them spanning multiple string values. (NOTE: mypy, pytype, pyre do
@@ -820,6 +822,8 @@ def _validate_msg(line: Line, string_idx: int) -> TResult[None]:
820822
821823 i += inc
822824
825+ QUOTE = line .leaves [string_idx ].value [- 1 ]
826+
823827 num_of_inline_string_comments = 0
824828 set_of_prefixes = set ()
825829 num_of_strings = 0
@@ -842,6 +846,19 @@ def _validate_msg(line: Line, string_idx: int) -> TResult[None]:
842846
843847 set_of_prefixes .add (prefix )
844848
849+ if (
850+ "f" in prefix
851+ and leaf .value [- 1 ] != QUOTE
852+ and (
853+ "'" in leaf .value [len (prefix ) + 1 : - 1 ]
854+ or '"' in leaf .value [len (prefix ) + 1 : - 1 ]
855+ )
856+ ):
857+ return TErr (
858+ "StringMerger does NOT merge f-strings with different quote types"
859+ "and internal quotes."
860+ )
861+
845862 if id (leaf ) in line .comments :
846863 num_of_inline_string_comments += 1
847864 if contains_pragma_comment (line .comments [id (leaf )]):
0 commit comments