diff -r 35a9d60145cd Modules/_dbmmodule.c --- a/Modules/_dbmmodule.c Fri Apr 17 04:58:45 2015 +0300 +++ b/Modules/_dbmmodule.c Sun Apr 19 11:38:39 2015 -0700 @@ -272,7 +272,7 @@ self: dbmobject - key: str(types={'str', 'robuffer'}, length=True) + key: str(types={str, robuffer}, length=True) default: object = None / @@ -282,7 +282,7 @@ static PyObject * dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, PyObject *default_value) -/*[clinic end generated code: output=4f5c0e523eaf1251 input=f81478bc211895ef]*/ +/*[clinic end generated code: output=4f5c0e523eaf1251 input=c513a2930092cc9d]*/ { datum dbm_key, val; diff -r 35a9d60145cd Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Fri Apr 17 04:58:45 2015 +0300 +++ b/Modules/_io/bufferedio.c Sun Apr 19 11:38:39 2015 -0700 @@ -101,26 +101,26 @@ /*[clinic input] _io._BufferedIOBase.readinto - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / [clinic start generated code]*/ static PyObject * _io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer) -/*[clinic end generated code: output=8c8cda6684af8038 input=f8242a06c21763a0]*/ +/*[clinic end generated code: output=8c8cda6684af8038 input=076e49a36bb37af1]*/ { return _bufferediobase_readinto_generic(self, buffer, 0); } /*[clinic input] _io._BufferedIOBase.readinto1 - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / [clinic start generated code]*/ static PyObject * _io__BufferedIOBase_readinto1_impl(PyObject *self, Py_buffer *buffer) -/*[clinic end generated code: output=358623e4fd2b69d3 input=2003e706c730bd21]*/ +/*[clinic end generated code: output=358623e4fd2b69d3 input=8c85e1fb51fc9c99]*/ { return _bufferediobase_readinto_generic(self, buffer, 1); } @@ -1065,26 +1065,26 @@ /*[clinic input] _io._Buffered.readinto - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / [clinic start generated code]*/ static PyObject * _io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer) -/*[clinic end generated code: output=bcb376580b1d8170 input=962b7496eac38b3a]*/ +/*[clinic end generated code: output=bcb376580b1d8170 input=ce115d72f68e9254]*/ { return _buffered_readinto_generic(self, buffer, 0); } /*[clinic input] _io._Buffered.readinto1 - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / [clinic start generated code]*/ static PyObject * _io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer) -/*[clinic end generated code: output=6e5c6ac5868205d6 input=834614d93f0adeb5]*/ +/*[clinic end generated code: output=6e5c6ac5868205d6 input=45c1263f4cdfde47]*/ { return _buffered_readinto_generic(self, buffer, 1); } diff -r 35a9d60145cd Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c Fri Apr 17 04:58:45 2015 +0300 +++ b/Modules/_io/bytesio.c Sun Apr 19 11:38:39 2015 -0700 @@ -541,7 +541,7 @@ /*[clinic input] _io.BytesIO.readinto - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / Read up to len(buffer) bytes into buffer. @@ -552,7 +552,7 @@ static PyObject * _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) -/*[clinic end generated code: output=a5d407217dcf0639 input=d289da851c7c4159]*/ +/*[clinic end generated code: output=a5d407217dcf0639 input=cdca8e493d75ad72]*/ { Py_ssize_t len, n; diff -r 35a9d60145cd Modules/_io/fileio.c --- a/Modules/_io/fileio.c Fri Apr 17 04:58:45 2015 +0300 +++ b/Modules/_io/fileio.c Sun Apr 19 11:38:39 2015 -0700 @@ -604,7 +604,7 @@ /*[clinic input] _io.FileIO.readinto - buffer: Py_buffer(types={'rwbuffer'}) + buffer: Py_buffer(types={rwbuffer}) / Same as RawIOBase.readinto(). @@ -612,7 +612,7 @@ static PyObject * _io_FileIO_readinto_impl(fileio *self, Py_buffer *buffer) -/*[clinic end generated code: output=b01a5a22c8415cb4 input=5edd8327498d468c]*/ +/*[clinic end generated code: output=b01a5a22c8415cb4 input=045b19325ec5dcf8]*/ { Py_ssize_t n; int err; diff -r 35a9d60145cd Modules/arraymodule.c --- a/Modules/arraymodule.c Fri Apr 17 04:58:45 2015 +0300 +++ b/Modules/arraymodule.c Sun Apr 19 11:38:39 2015 -0700 @@ -1600,7 +1600,7 @@ /*[clinic input] array.array.fromstring - buffer: Py_buffer(types={'str', 'buffer'}) + buffer: Py_buffer(types={str, buffer}) / Appends items from the string, interpreting it as an array of machine values, as if it had been read from a file using the fromfile() method). @@ -1610,7 +1610,7 @@ static PyObject * array_array_fromstring_impl(arrayobject *self, Py_buffer *buffer) -/*[clinic end generated code: output=31c4baa779df84ce input=fdde1a56cbe2b05b]*/ +/*[clinic end generated code: output=31c4baa779df84ce input=1303b97380a50a03]*/ { if (PyErr_WarnEx(PyExc_DeprecationWarning, "fromstring() is deprecated. Use frombytes() instead.", 2) != 0) @@ -1929,7 +1929,7 @@ array._array_reconstructor arraytype: object(type="PyTypeObject *") - typecode: int(types={'str'}) + typecode: int(types={str}) mformat_code: int(type="enum machine_format_code") items: object / @@ -1942,7 +1942,7 @@ int typecode, enum machine_format_code mformat_code, PyObject *items) -/*[clinic end generated code: output=6ecbf0e8e4d92ab9 input=a9ae223306d7b262]*/ +/*[clinic end generated code: output=6ecbf0e8e4d92ab9 input=eeae27b3cf2d7c16]*/ { PyObject *converted_items; PyObject *result; diff -r 35a9d60145cd Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Fri Apr 17 04:58:45 2015 +0300 +++ b/Tools/clinic/clinic.py Sun Apr 19 11:38:39 2015 -0700 @@ -26,8 +26,12 @@ import tempfile import textwrap import traceback +import types import uuid +from types import * +NoneType = type(None) + # TODO: # # soon: @@ -2531,17 +2535,17 @@ if not bitwise: fail("Unsigned shorts must be bitwise (for now).") -@add_legacy_c_converter('C', types={'str'}) +@add_legacy_c_converter('C', types={str}) class int_converter(CConverter): type = 'int' default_type = int format_unit = 'i' c_ignored_default = "0" - def converter_init(self, *, types={'int'}, type=None): - if types == {'str'}: + def converter_init(self, *, types={int}, type=None): + if types == {str}: self.format_unit = 'C' - elif types != {'int'}: + elif types != {int}: fail("int_converter: illegal 'types' argument " + repr(types)) if type != None: self.type = type @@ -2634,17 +2638,22 @@ # -# We define three string conventions for buffer types in the 'types' argument: -# 'buffer' : any object supporting the buffer interface -# 'rwbuffer': any object supporting the buffer interface, but must be writeable -# 'robuffer': any object supporting the buffer interface, but must not be writeable +# We define three conventions for buffer types in the 'types' argument: # - -@add_legacy_c_converter('s#', types={"str", "robuffer"}, length=True) -@add_legacy_c_converter('y', types={"robuffer"}) -@add_legacy_c_converter('y#', types={"robuffer"}, length=True) +# buffer : any object supporting the buffer interface +# rwbuffer: any object supporting the buffer interface, but must be writeable +# robuffer: any object supporting the buffer interface, but must not be writeable +# + +class buffer: pass +class rwbuffer: pass +class robuffer: pass + +@add_legacy_c_converter('s#', types={str, robuffer}, length=True) +@add_legacy_c_converter('y', types={robuffer}) +@add_legacy_c_converter('y#', types={robuffer}, length=True) @add_legacy_c_converter('z', nullable=True) -@add_legacy_c_converter('z#', types={"str", "robuffer"}, nullable=True, length=True) +@add_legacy_c_converter('z#', types={str, robuffer}, nullable=True, length=True) # add_legacy_c_converter not supported for es, es#, et, et# # because of their extra encoding argument class str_converter(CConverter): @@ -2652,15 +2661,15 @@ default_type = (str, Null, NoneType) format_unit = 's' - def converter_init(self, *, encoding=None, types={"str"}, + def converter_init(self, *, encoding=None, types={str}, length=False, nullable=False, zeroes=False): self.length = bool(length) - is_b_or_ba = types == {"bytes", "bytearray"} - is_str = types == {"str"} - is_robuffer = types == {"robuffer"} - is_str_or_robuffer = types == {"str", "robuffer"} + is_b_or_ba = types == {bytes, bytearray} + is_str = types == {str} + is_robuffer = types == {robuffer} + is_str_or_robuffer = types == {str, robuffer} format_unit = None @@ -2728,29 +2737,29 @@ self.length = True self.format_unit = format_unit -@add_legacy_c_converter('s*', types={'str', 'buffer'}) -@add_legacy_c_converter('z*', types={'str', 'buffer'}, nullable=True) -@add_legacy_c_converter('w*', types={'rwbuffer'}) +@add_legacy_c_converter('s*', types={str, buffer}) +@add_legacy_c_converter('z*', types={str, buffer}, nullable=True) +@add_legacy_c_converter('w*', types={rwbuffer}) class Py_buffer_converter(CConverter): type = 'Py_buffer' format_unit = 'y*' impl_by_reference = True c_ignored_default = "{NULL, NULL}" - def converter_init(self, *, types={'buffer'}, nullable=False): + def converter_init(self, *, types={buffer}, nullable=False): if self.default not in (unspecified, None): fail("The only legal default value for Py_buffer is None.") self.c_default = self.c_ignored_default format_unit = None - if types == {'str', 'buffer'}: + if types == {str, buffer}: format_unit = 's*' if not nullable else 'z*' else: if nullable: fail('Py_buffer_converter: illegal combination of arguments (nullable=True)') - elif types == {'buffer'}: + elif types == {buffer}: format_unit = 'y*' - elif types == {'rwbuffer'}: + elif types == {rwbuffer}: format_unit = 'w*' if not format_unit: fail("Py_buffer_converter: illegal combination of arguments") @@ -3035,6 +3044,27 @@ 'return_value = PyUnicode_DecodeFSDefault(_return_value);\n') +def eval_ast_expr(node, symbols=None, *, filename='-'): + """ + Takes an ast.Expr node. Compiles and evaluates it. + Returns the result of the expression. + + symbols represents the globals dict the expression + should see. (There's no equivalent for "locals" here.) + """ + + if isinstance(node, ast.Expr): + node = node.value + + if symbols == None: + symbols = globals() + + node = ast.Expression(node) + co = compile(node, filename, 'eval') + fn = types.FunctionType(co, symbols) + return fn() + + class IndentStack: def __init__(self): self.indents = [] @@ -3795,7 +3825,9 @@ fail("Annotations must be either a name, a function call, or a string.") name = annotation.func.id - kwargs = {node.arg: ast.literal_eval(node.value) for node in annotation.keywords} + symbols = globals() + + kwargs = {node.arg: eval_ast_expr(node.value, symbols) for node in annotation.keywords} return name, False, kwargs def parse_special_symbol(self, symbol):