Skip to content

Commit

Permalink
prevent tp_new() optimisation from breaking external types with known…
Browse files Browse the repository at this point in the history
… typeobj
  • Loading branch information
scoder committed Mar 29, 2013
1 parent dd29ccb commit 3257193
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Cython/Compiler/Optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,9 @@ def _handle_any_slot__new__(self, node, function, args,

if type_arg.type_entry:
ext_type = type_arg.type_entry.type
if ext_type.is_extension_type and ext_type.typeobj_cname:
if (ext_type.is_extension_type and ext_type.typeobj_cname and
ext_type.scope.global_scope() == self.current_env().global_scope()):
# known type in current module
tp_slot = TypeSlots.ConstructorSlot("tp_new", '__new__')
slot_func_cname = TypeSlots.get_slot_function(ext_type.scope, tp_slot)
if slot_func_cname:
Expand Down
2 changes: 1 addition & 1 deletion tests/run/tp_new_cimport.srctree
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_sub():

######## a.pxd ########

cdef class ExtTypeA:
cdef api class ExtTypeA[type ExtTypeA_Type, object ExtTypeAObject]:
cdef readonly attrA

######## a.pyx ########
Expand Down

0 comments on commit 3257193

Please sign in to comment.