summaryrefslogtreecommitdiffstats
path: root/Python/codegen.c
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-11-26 15:40:13 (GMT)
committerGitHub <noreply@github.com>2024-11-26 15:40:13 (GMT)
commitdcf629213bc046318c862ec0af5db3dfd1fc473a (patch)
tree95b5742a1fc2b20f4348d10746f7e520d75cde0d /Python/codegen.c
parent2b0e2b2893a821ca36cd65a204bed932741ac189 (diff)
downloadcpython-dcf629213bc046318c862ec0af5db3dfd1fc473a.zip
cpython-dcf629213bc046318c862ec0af5db3dfd1fc473a.tar.gz
cpython-dcf629213bc046318c862ec0af5db3dfd1fc473a.tar.bz2
gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415)
Diffstat (limited to 'Python/codegen.c')
-rw-r--r--Python/codegen.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index dbf36cd..a5e550c 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -24,6 +24,7 @@
#include "pycore_instruction_sequence.h" // _PyInstructionSequence_NewLabel()
#include "pycore_intrinsics.h"
#include "pycore_long.h" // _PyLong_GetZero()
+#include "pycore_object.h" // _Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS
#include "pycore_pystate.h" // _Py_GetConfig()
#include "pycore_symtable.h" // PySTEntryObject
@@ -672,14 +673,16 @@ codegen_setup_annotations_scope(compiler *c, location loc,
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
key, loc.lineno, NULL, &umd));
+ // if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
+ PyObject *value_with_fake_globals = PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
- // if .format != 1: raise NotImplementedError
_Py_DECLARE_STR(format, ".format");
ADDOP_I(c, loc, LOAD_FAST, 0);
- ADDOP_LOAD_CONST(c, loc, _PyLong_GetOne());
- ADDOP_I(c, loc, COMPARE_OP, (Py_NE << 5) | compare_masks[Py_NE]);
+ ADDOP_LOAD_CONST(c, loc, value_with_fake_globals);
+ ADDOP_I(c, loc, COMPARE_OP, (Py_GT << 5) | compare_masks[Py_GT]);
NEW_JUMP_TARGET_LABEL(c, body);
ADDOP_JUMP(c, loc, POP_JUMP_IF_FALSE, body);
+
ADDOP_I(c, loc, LOAD_COMMON_CONSTANT, CONSTANT_NOTIMPLEMENTEDERROR);
ADDOP_I(c, loc, RAISE_VARARGS, 1);
USE_LABEL(c, body);