diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-12-28 06:47:50 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-12-28 06:47:50 (GMT) |
commit | c150536b5efadf71fcb4187cad7258be7268e157 (patch) | |
tree | aeb17f5e0ecc6cc8ccdecb2b64e3f46a0a3af85c /Python/ceval.c | |
parent | f6657e67b3cf89649d14d9012b3964a3490d45b0 (diff) | |
download | cpython-c150536b5efadf71fcb4187cad7258be7268e157.zip cpython-c150536b5efadf71fcb4187cad7258be7268e157.tar.gz cpython-c150536b5efadf71fcb4187cad7258be7268e157.tar.bz2 |
PEP 3107 - Function Annotations thanks to Tony Lownds
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 82aa668..f5ebb8e 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2293,10 +2293,37 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) { int posdefaults = oparg & 0xff; int kwdefaults = (oparg>>8) & 0xff; + int num_annotations = (oparg >> 16) & 0x7fff; v = POP(); /* code object */ x = PyFunction_New(v, f->f_globals); Py_DECREF(v); + + if (x != NULL && num_annotations > 0) { + Py_ssize_t name_ix; + u = POP(); /* names of args with annotations */ + v = PyDict_New(); + if (v == NULL) { + Py_DECREF(x); + x = NULL; + break; + } + name_ix = PyTuple_Size(u); + assert(num_annotations == name_ix+1); + while (name_ix > 0) { + --name_ix; + t = PyTuple_GET_ITEM(u, name_ix); + w = POP(); + /* XXX(nnorwitz): check for errors */ + PyDict_SetItem(v, t, w); + Py_DECREF(w); + } + + err = PyFunction_SetAnnotations(x, v); + Py_DECREF(v); + Py_DECREF(u); + } + /* XXX Maybe this should be a separate opcode? */ if (x != NULL && posdefaults > 0) { v = PyTuple_New(posdefaults); @@ -2322,6 +2349,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) while (--kwdefaults >= 0) { w = POP(); /* default value */ u = POP(); /* kw only arg name */ + /* XXX(nnorwitz): check for errors */ PyDict_SetItem(v, u, w); } err = PyFunction_SetKwDefaults(x, v); |