PY-79967 Support t-prefixed strings, Related PR: https://github.com/JetBrains/intellij-community/pull/302

* Add PYTHON314_PREFIXES to CompatibilityVisitor
* Patch typeshed, add t-string related stubs
* Infer `string.templatelib.Template` type for t-strings instead of plain `str`



GitOrigin-RevId: 0e913910ab9e0dca4052856b0585ce66265291c0
This commit is contained in:
Koudai Aono
2024-09-16 04:46:29 +09:00
committed by intellij-monorepo-bot
parent a1846f3078
commit 7239d2ef2c
11 changed files with 787 additions and 638 deletions

View File

@@ -85,7 +85,7 @@ ONE_TWO_APOS = ('[^\\']) | ('\\[^]) | (''[^\\']) | (''\\[^])
APOS_STRING_CHAR = [^\\'] | {ANY_ESCAPE_SEQUENCE} | {ONE_TWO_APOS}
TRIPLE_APOS_LITERAL = {THREE_APOS} {APOS_STRING_CHAR}* {THREE_APOS}?
FSTRING_PREFIX = [UuBbCcRr]{0,3}[fF][UuBbCcRr]{0,3}
FSTRING_PREFIX = [UuBbCcRr]{0,3}[fFtT][UuBbCcRr]{0,3}
FSTRING_START = {FSTRING_PREFIX} (\"\"\"|'''|\"|')
FSTRING_QUOTES = (\"{1,3}|'{1,3})
FSTRING_ESCAPED_LBRACE = "{{"

View File

@@ -109,7 +109,7 @@ public class ExpressionParsing extends Parsing {
if (atToken(PyTokenTypes.FSTRING_START)) {
final String prefixThenQuotes = builder.getTokenText();
assert prefixThenQuotes != null;
final String openingQuotes = prefixThenQuotes.replaceFirst("^[UuBbCcRrFf]*", "");
final String openingQuotes = prefixThenQuotes.replaceFirst("^[UuBbCcRrFfTt]*", "");
final SyntaxTreeBuilder.Marker marker = builder.mark();
nextToken();
while (true) {

View File

@@ -11,7 +11,7 @@ public class PyStringLiteralCoreUtil {
/**
* Valid string prefix characters (lowercased) as defined in Python lexer.
*/
public static final String PREFIX_CHARACTERS = "ubcrf";
public static final String PREFIX_CHARACTERS = "ubcrft";
/**
* Maximum length of a string prefix as defined in Python lexer.

View File

@@ -99,7 +99,7 @@ public final class PyStringLiteralUtil extends PyStringLiteralCoreUtil {
* @return whether the given prefix contains either 'f' or 'F' character
*/
public static boolean isFormattedPrefix(@NotNull String prefix) {
return StringUtil.indexOfIgnoreCase(prefix, 'f', 0) >= 0;
return StringUtil.indexOfIgnoreCase(prefix, 'f', 0) >= 0 | StringUtil.indexOfIgnoreCase(prefix, 't', 0) >= 0;
}
/**