8000 Implement next version of PEP 750 · python/cpython@9248287 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9248287

Browse files
committed
Implement next version of PEP 750
Still buggy
1 parent 6d93690 commit 9248287

38 files changed

+3042
-1604
lines changed

Doc/library/token-list.inc

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Grammar/Tokens

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ TYPE_IGNORE
6060
TYPE_COMMENT
6161
SOFT_KEYWORD
6262
FSTRING_START
63+
TSTRING_START
6364
FSTRING_MIDDLE
6465
FSTRING_END
6566
COMMENT

Grammar/python.gram

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ literal_pattern[pattern_ty]:
500500
literal_expr[expr_ty]:
501501
| signed_number !('+' | '-')
502502
| complex_number
503-
| strings
503+
| &(STRING|FSTRING_START) strings
504504
| 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) }
505505
| 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) }
506506
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
@@ -841,6 +841,7 @@ atom[expr_ty]:
841841
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
842842
| 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) }
843843
| &(STRING|FSTRING_START) strings
844+
| &TSTRING_START tstring
844845
| NUMBER
845846
| &'(' (tuple | group | genexp)
846847
| &'[' (list | listcomp)
@@ -927,6 +928,16 @@ fstring_format_spec[expr_ty]:
927928
fstring[expr_ty]:
928929
| a=FSTRING_START b=fstring_middle* c=FSTRING_END { _PyPegen_joined_str(p, a, (asdl_expr_seq*)b, c) }
929930

931+
tstring_middle[expr_ty]:
932+
| tstring_replacement_field
933+
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
934+
tstring_replacement_field[expr_ty]:
935+
| '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
936+
_PyPegen_interpolation(p, a, debug_expr, conversion, format, rbrace, EXTRA) }
937+
| invalid_replacement_field
938+
tstring[expr_ty]:
939+
| a=TSTRING_START b=tstring_middle* c=FSTRING_END { _PyPegen_template_str(p, a, (asdl_expr_seq*)b, c) }
940+
930941
string[expr_ty]: s[Token*]=STRING { _PyPegen_constant_from_string(p, s) }
931942
strings[expr_ty] (memo): a[asdl_expr_seq*]=(fstring|string)+ { _PyPegen_concatenate_strings(p, a, EXTRA) }
932943

Include/internal/pycore_ast.h

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_ast_state.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef Py_INTERNAL_INTERPOLATION_H
2+
#define Py_INTERNAL_INTERPOLATION_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#ifndef Py_BUILD_CORE
9+
# error "this header requires Py_BUILD_CORE define"
10+
#endif
11+
12+
typedef struct {
13+
PyObject_HEAD
14+
PyObject *value;
15+
PyObject *expr;
16+
PyObject *conv;
17+
PyObject *format_spec;
18+
} PyInterpolationObject;
19+
20+
extern PyTypeObject PyInterpolation_Type;
21+
22+
PyAPI_FUNC(PyObject *) _PyInterpolation_FromStackRefSteal(_PyStackRef *values, Py_ssize_t n);
23+
24+
extern PyStatus _PyInterpolation_InitTypes(PyInterpreterState *);
25+
extern void _PyInterpolation_FiniTypes(PyInterpreterState *);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif
30+
31+
#endif

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Known values:
260260
Python 3.14a1 3606 (Specialize CALL_KW)
261261
Python 3.14a1 3607 (Add pseudo instructions JUMP_IF_TRUE/FALSE)
262262
Python 3.14a1 3608 (Add support for slices)
263+
Python 3.14a1 3609 (Add BUILD_INTERPOLATION & BUILD_TEMPLATE opcodes)
263264
264265
Python 3.15 will start with 3650
265266
@@ -272,7 +273,7 @@ PC/launcher.c must also be updated.
272273
273274
*/
274275

275-
#define PYC_MAGIC_NUMBER 3608
276+
#define PYC_MAGIC_NUMBER 3609
276277
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
277278
(little-endian) and then appending b'\r\n'. */
278279
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_template.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef Py_INTERNAL_TEMPLATE_H
2+
#define Py_INTERNAL_TEMPLATE_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#ifndef Py_BUILD_CORE
9+
# error "this header requires Py_BUILD_CORE define"
10+
#endif
11+
12+
typedef struct {
13+
PyObject_HEAD
14+
PyObject *args;
15+
} PyTemplateObject;
16+
17+
extern PyTypeObject PyTemplate_Type;
18+
19+
PyAPI_FUNC(PyObject *) _PyTemplate_Create(PyObject **values, Py_ssize_t n);
20+
21+
extern PyStatus _PyTemplate_InitTypes(PyInterpreterState *);
22+
extern void _PyTemplate_FiniTypes(PyInterpreterState *);
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
#endif

Include/internal/pycore_token.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ extern "C" {
7373
#define TYPE_COMMENT 57
7474
#define SOFT_KEYWORD 58
7575
#define FSTRING_START 59
76-
#define FSTRING_MIDDLE 60
77-
#define FSTRING_END 61
78-
#define COMMENT 62
79-
#define NL 63
80-
#define ERRORTOKEN 64
81-
#define N_TOKENS 66
76+
#define TSTRING_START 60
77+
#define FSTRING_MIDDLE 61
78+
#define FSTRING_END 62
79+
#define COMMENT 63
80+
#define NL 64
81+
#define ERRORTOKEN 65
82+
#define N_TOKENS 67
8283
#define NT_OFFSET 256
8384

8485
/* Special definitions for cooperation with parser */

Include/internal/pycore_uop_ids.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0