diff options
author | mattip <matti.picus@gmail.com> | 2019-01-16 16:39:00 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2019-01-16 16:39:00 +0200 |
commit | 499fd67877523dda911121a20eaa9f51f4ca3d2b (patch) | |
tree | 91e1182313060ff5b4aef67437865f8af9399d0b | |
parent | ccb670888dd23a79c4aa1c027806acdc782b1bf3 (diff) | |
download | cython-499fd67877523dda911121a20eaa9f51f4ca3d2b.tar.gz |
MAINT: fixes from review
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 2 | ||||
-rw-r--r-- | Cython/Compiler/Nodes.py | 27 | ||||
-rw-r--r-- | Cython/Compiler/Symtab.py | 3 | ||||
-rw-r--r-- | tests/run/ext_attr_getter.srctree | 21 |
4 files changed, 33 insertions, 20 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 8598f8ff8..5f3683603 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -7147,7 +7147,7 @@ class AttributeNode(ExprNode): #print "...obj_code =", obj_code ### if self.entry and self.entry.is_cmethod: if self.entry.is_cgetter: - return "%s(%s)" %(self.entry.func_cname, obj_code) + return "%s(%s)" % (self.entry.func_cname, obj_code) if obj.type.is_extension_type and not self.entry.is_builtin_cmethod: if self.entry.final_func_cname: return self.entry.final_func_cname diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index c854cf768..2a66a2d92 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2351,6 +2351,9 @@ class CFuncDefNode(FuncDefNode): pass else: error(self.pos, "Cannot handle %s decorators yet" % func.name) + else: + error(self.pos, + "Cannot handle %s decorators yet" % type(func).__name__) self.is_c_class_method = env.is_c_class_scope if self.directive_locals is None: @@ -2366,20 +2369,20 @@ class CFuncDefNode(FuncDefNode): self.is_static_method = 'staticmethod' in env.directives and not env.lookup_here('staticmethod') # The 2 here is because we need both function and argument names. if isinstance(self.declarator, CFuncDeclaratorNode): - name_declarator, type = self.declarator.analyse( + name_declarator, typ = self.declarator.analyse( base_type, env, nonempty=2 * (self.body is not None), directive_locals=self.directive_locals, visibility=self.visibility) else: - name_declarator, type = self.declarator.analyse( + name_declarator, typ = self.declarator.analyse( base_type, env, nonempty=2 * (self.body is not None), visibility=self.visibility) - if not type.is_cfunction: + if not typ.is_cfunction: error(self.pos, "Suite attached to non-function declaration") # Remember the actual type according to the function header # written here, because the type in the symbol table entry # may be different if we're overriding a C method inherited # from the base type of an extension type. - self.type = type - type.is_overridable = self.overridable + self.type = typ + typ.is_overridable = self.overridable declarator = self.declarator while not hasattr(declarator, 'args'): declarator = declarator.base @@ -2392,11 +2395,11 @@ class CFuncDefNode(FuncDefNode): error(self.cfunc_declarator.pos, "Function with optional arguments may not be declared public or api") - if type.exception_check == '+' and self.visibility != 'extern': + if typ.exception_check == '+' and self.visibility != 'extern': warning(self.cfunc_declarator.pos, "Only extern functions can throw C++ exceptions.") - for formal_arg, type_arg in zip(self.args, type.args): + for formal_arg, type_arg in zip(self.args, typ.args): self.align_argument_type(env, type_arg) formal_arg.type = type_arg.type formal_arg.name = type_arg.name @@ -2417,16 +2420,16 @@ class CFuncDefNode(FuncDefNode): elif 'inline' in self.modifiers: warning(formal_arg.pos, "Buffer unpacking not optimized away.", 1) - self._validate_type_visibility(type.return_type, self.pos, env) + self._validate_type_visibility(typ.return_type, self.pos, env) name = name_declarator.name cname = name_declarator.cname - type.is_const_method = self.is_const_method - type.is_static_method = self.is_static_method + typ.is_const_method = self.is_const_method + typ.is_static_method = self.is_static_method self.entry = env.declare_cfunction( - name, type, self.pos, + name, typ, self.pos, cname=cname, visibility=self.visibility, api=self.api, defining=self.body is not None, modifiers=self.modifiers, overridable=self.overridable) @@ -2435,7 +2438,7 @@ class CFuncDefNode(FuncDefNode): env.property_entries.append(self.entry) env.cfunc_entries.remove(self.entry) self.entry.inline_func_in_pxd = self.inline_in_pxd - self.return_type = type.return_type + self.return_type = typ.return_type if self.return_type.is_array and self.visibility != 'extern': error(self.pos, "Function cannot return an array") if self.return_type.is_cpp_class: diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 7ed8d4c74..fb30c6ef6 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -754,8 +754,7 @@ class Scope(object): def declare_cfunction(self, name, type, pos, cname=None, visibility='private', api=0, in_pxd=0, - defining=0, modifiers=(), utility_code=None, - overridable=False): + defining=0, modifiers=(), utility_code=None, overridable=False): # Add an entry for a C function. if not cname: if visibility != 'private' or api: diff --git a/tests/run/ext_attr_getter.srctree b/tests/run/ext_attr_getter.srctree index 247b18acd..69eb04c47 100644 --- a/tests/run/ext_attr_getter.srctree +++ b/tests/run/ext_attr_getter.srctree @@ -12,11 +12,12 @@ setup(ext_modules= cythonize("foo_extension.pyx", language_level=3)) setup(ext_modules = cythonize("getter[0-9].pyx", language_level=3)) -try: - cythonize("getter_fail0.pyx", language_level=3) - assert False -except CompileError: - print("\nGot expected exception, continuing\n") +for name in ("getter_fail0.pyx", "getter_fail1.pyx"): + try: + cythonize(name, language_level=3) + assert False + except CompileError as e: + print("\nGot expected exception, continuing\n") ######## foo.h ######## @@ -154,6 +155,16 @@ cdef extern from "foo.h": cdef void field0(): print('in staticmethod of Foo') +######## getter_fail1.pyx ######## + +# Make sure not all decorators are accepted +cimport cython + +cdef extern from "foo.h": + ctypedef class foo_extension.Foo [object FooStructOpaque]: + @prop.getter + cdef void field0(self): + pass ######## runner.py ######## |