Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -993,13 +993,6 @@ All of the following opcodes use their arguments.
Deletes local ``co_varnames[var_num]``.


.. opcode:: STORE_ANNOTATION (namei)

Stores TOS as ``locals()['__annotations__'][co_names[namei]] = TOS``.

.. versionadded:: 3.6


.. opcode:: LOAD_CLOSURE (i)

Pushes a reference to the cell contained in slot *i* of the cell and free
Expand Down
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@ CPython bytecode changes
* Added two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`CALL_METHOD`.
(Contributed by Yury Selivanov and INADA Naoki in :issue:`26110`.)

* Removed the STORE_ANNOTATION opcode.


Other CPython implementation changes
------------------------------------
Expand Down
1 change: 0 additions & 1 deletion Include/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ extern "C" {
#define LOAD_FAST 124
#define STORE_FAST 125
#define DELETE_FAST 126
#define STORE_ANNOTATION 127
#define RAISE_VARARGS 130
#define CALL_FUNCTION 131
#define MAKE_FUNCTION 132
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.7a0 3390 (add LOAD_METHOD and CALL_METHOD opcodes)
# Python 3.7a0 3391 (update GET_AITER #31709)
# Python 3.7a0 3392 (PEP 552: Deterministic pycs)
# Python 3.7a0 3393 (remove STORE_ANNOTATION opcode)
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
# longer be understood by older implementations of the eval loop (usually
Expand All @@ -250,7 +251,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3392).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3393).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
1 change: 0 additions & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def jabs_op(name, op):
haslocal.append(125)
def_op('DELETE_FAST', 126) # Local variable number
haslocal.append(126)
name_op('STORE_ANNOTATION', 127) # Index in name list

def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
def_op('CALL_FUNCTION', 131) # #args
Expand Down
38 changes: 21 additions & 17 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,27 @@ def bug1333982(x=[]):
2 LOAD_CONST 0 (1)
4 STORE_NAME 0 (x)
6 LOAD_NAME 1 (int)
8 STORE_ANNOTATION 0 (x)

3 10 LOAD_NAME 2 (fun)
12 LOAD_CONST 0 (1)
14 CALL_FUNCTION 1
16 STORE_ANNOTATION 3 (y)

4 18 LOAD_CONST 0 (1)
20 LOAD_NAME 4 (lst)
22 LOAD_NAME 2 (fun)
24 LOAD_CONST 1 (0)
26 CALL_FUNCTION 1
28 STORE_SUBSCR
30 LOAD_NAME 1 (int)
32 POP_TOP
34 LOAD_CONST 2 (None)
36 RETURN_VALUE
8 LOAD_NAME 2 (__annotations__)
10 LOAD_CONST 1 ('x')
12 STORE_SUBSCR

3 14 LOAD_NAME 3 (fun)
16 LOAD_CONST 0 (1)
18 CALL_FUNCTION 1
20 LOAD_NAME 2 (__annotations__)
22 LOAD_CONST 2 ('y')
24 STORE_SUBSCR

4 26 LOAD_CONST 0 (1)
28 LOAD_NAME 4 (lst)
30 LOAD_NAME 3 (fun)
32 LOAD_CONST 3 (0)
34 CALL_FUNCTION 1
36 STORE_SUBSCR
38 LOAD_NAME 1 (int)
40 POP_TOP
42 LOAD_CONST 4 (None)
44 RETURN_VALUE
"""

compound_stmt_str = """\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the STORE_ANNOTATION bytecode.
55 changes: 0 additions & 55 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,61 +1574,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
DISPATCH();
}

TARGET(STORE_ANNOTATION) {
_Py_IDENTIFIER(__annotations__);
PyObject *ann_dict;
PyObject *ann = POP();
PyObject *name = GETITEM(names, oparg);
int err;
if (f->f_locals == NULL) {
PyErr_Format(PyExc_SystemError,
"no locals found when storing annotation");
Py_DECREF(ann);
goto error;
}
/* first try to get __annotations__ from locals... */
if (PyDict_CheckExact(f->f_locals)) {
ann_dict = _PyDict_GetItemId(f->f_locals,
&PyId___annotations__);
if (ann_dict == NULL) {
PyErr_SetString(PyExc_NameError,
"__annotations__ not found");
Py_DECREF(ann);
goto error;
}
Py_INCREF(ann_dict);
}
else {
PyObject *ann_str = _PyUnicode_FromId(&PyId___annotations__);
if (ann_str == NULL) {
Py_DECREF(ann);
goto error;
}
ann_dict = PyObject_GetItem(f->f_locals, ann_str);
if (ann_dict == NULL) {
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_SetString(PyExc_NameError,
"__annotations__ not found");
}
Py_DECREF(ann);
goto error;
}
}
/* ...if succeeded, __annotations__[name] = ann */
if (PyDict_CheckExact(ann_dict)) {
err = PyDict_SetItem(ann_dict, name, ann);
}
else {
err = PyObject_SetItem(ann_dict, name, ann);
}
Py_DECREF(ann_dict);
Py_DECREF(ann);
if (err != 0) {
goto error;
}
DISPATCH();
}

TARGET(DELETE_SUBSCR) {
PyObject *sub = TOP();
PyObject *container = SECOND();
Expand Down
16 changes: 10 additions & 6 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static int compiler_async_comprehension_generator(
expr_ty elt, expr_ty val, int type);

static PyCodeObject *assemble(struct compiler *, int addNone);
static PyObject *__doc__;
static PyObject *__doc__, *__annotations__;

#define CAPSULE_NAME "compile.c compiler unit"

Expand Down Expand Up @@ -311,7 +311,11 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
if (!__doc__)
return NULL;
}

if (!__annotations__) {
__annotations__ = PyUnicode_InternFromString("__annotations__");
if (!__annotations__)
return NULL;
}
if (!compiler_init(&c))
return NULL;
Py_INCREF(filename);
Expand Down Expand Up @@ -1056,8 +1060,6 @@ stack_effect(int opcode, int oparg, int jump)
return -1;
case DELETE_FAST:
return 0;
case STORE_ANNOTATION:
return -1;

case RAISE_VARARGS:
return -oparg;
Expand Down Expand Up @@ -4711,8 +4713,10 @@ compiler_annassign(struct compiler *c, stmt_ty s)
else {
VISIT(c, expr, s->v.AnnAssign.annotation);
}
/* ADDOP_N decrefs its argument */
ADDOP_N(c, STORE_ANNOTATION, mangled, names);
ADDOP_NAME(c, LOAD_NAME, __annotations__, names);
ADDOP_O(c, LOAD_CONST, mangled, consts);
Py_DECREF(mangled);
ADDOP(c, STORE_SUBSCR);
}
break;
case Attribute_kind:
Expand Down
Loading