Skip to content

Commit bd7483e

Browse files
committed
unify string type checks
1 parent ad562e5 commit bd7483e

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

Include/internal/pycore_token.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ extern "C" {
9090
(x) == NEWLINE || \
9191
(x) == INDENT || \
9292
(x) == DEDENT)
93+
#define ISSTRINGLIT(x) ((x) == STRING || \
94+
(x) == FSTRING_MIDDLE || \
95+
(x) == FSTRING_END)
9396

9497

9598
// Symbols exported for test_peg_generator

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ token_setup(struct tok_state *tok, struct token *token, int type, const char *st
15631563
{
15641564
assert((start == NULL && end == NULL) || (start != NULL && end != NULL));
15651565
token->level = tok->level;
1566-
if (type == STRING || type == FSTRING_MIDDLE || type == FSTRING_END) {
1566+
if (ISSTRINGLIT(type)) {
15671567
token->lineno = tok->first_lineno;
15681568
}
15691569
else {

Python/Python-tokenize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ tokenizeriter_next(tokenizeriterobject *it)
8686
Py_DECREF(str);
8787
return NULL;
8888
}
89-
const char *line_start = type == STRING ? it->tok->multi_line_start : it->tok->line_start;
90-
int lineno = type == STRING ? it->tok->first_lineno : it->tok->lineno;
89+
const char *line_start = ISSTRINGLIT(type) ? it->tok->multi_line_start : it->tok->line_start;
90+
int lineno = ISSTRINGLIT(type) ? it->tok->first_lineno : it->tok->lineno;
9191
int end_lineno = it->tok->lineno;
9292
int col_offset = -1;
9393
int end_col_offset = -1;

Tools/build/generate_token.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def update_file(file, content):
8080
(x) == NEWLINE || \\
8181
(x) == INDENT || \\
8282
(x) == DEDENT)
83+
#define ISSTRINGLIT(x) ((x) == STRING || \\
84+
(x) == FSTRING_MIDDLE || \\
85+
(x) == FSTRING_END)
8386
8487
8588
// Symbols exported for test_peg_generator

0 commit comments

Comments
 (0)