summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-08-17 13:36:10 +0200
committerStefan Behnel <stefan_ml@behnel.de>2014-08-17 13:36:10 +0200
commitaee8b65a027bd2cfa4fe570fdbb070b807b5e4e0 (patch)
treeeedf561a79ae78ce872daf9457208c769be974f0
parent9b566f8eef97ba17dbb8d72dd57422f3f69af829 (diff)
downloadcython-aee8b65a027bd2cfa4fe570fdbb070b807b5e4e0.tar.gz
properly integrate Python class nodes into type inference
-rw-r--r--Cython/Compiler/ExprNodes.py16
-rw-r--r--Cython/Compiler/FlowControl.py6
2 files changed, 14 insertions, 8 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index d8b68401f..47958d0a2 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -7163,14 +7163,18 @@ class ClassNode(ExprNode, ModuleNameMixin):
# module_name EncodedString Name of defining module
subexprs = ['bases', 'doc']
+ type = py_object_type
+ is_temp = True
+
+ def infer_type(self, env):
+ # TODO: could return 'type' in some cases
+ return py_object_type
def analyse_types(self, env):
self.bases = self.bases.analyse_types(env)
if self.doc:
self.doc = self.doc.analyse_types(env)
self.doc = self.doc.coerce_to_pyobject(env)
- self.type = py_object_type
- self.is_temp = 1
env.use_utility_code(UtilityCode.load_cached("CreateClass", "ObjectHandling.c"))
return self
@@ -7215,10 +7219,14 @@ class Py3ClassNode(ExprNode):
# allow_py2_metaclass bool should look for Py2 metaclass
subexprs = []
+ type = py_object_type
+ is_temp = True
+
+ def infer_type(self, env):
+ # TODO: could return 'type' in some cases
+ return py_object_type
def analyse_types(self, env):
- self.type = py_object_type
- self.is_temp = 1
return self
def may_be_none(self):
diff --git a/Cython/Compiler/FlowControl.py b/Cython/Compiler/FlowControl.py
index 45d3cdd7e..c07e9edce 100644
--- a/Cython/Compiler/FlowControl.py
+++ b/Cython/Compiler/FlowControl.py
@@ -5,8 +5,7 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
Builtin=object, InternalError=object,
error=object, warning=object,
py_object_type=object, unspecified_type=object,
- object_expr=object, object_expr_not_none=object,
- fake_rhs_expr=object, TypedExprNode=object)
+ object_expr=object, fake_rhs_expr=object, TypedExprNode=object)
from . import Builtin
from . import ExprNodes
@@ -29,7 +28,6 @@ class TypedExprNode(ExprNodes.ExprNode):
return self._may_be_none != False
object_expr = TypedExprNode(py_object_type, may_be_none=True)
-object_expr_not_none = TypedExprNode(py_object_type, may_be_none=False)
# Fake rhs to silence "unused variable" warning
fake_rhs_expr = TypedExprNode(unspecified_type)
@@ -1287,7 +1285,7 @@ class ControlFlowAnalysis(CythonTransform):
def visit_PyClassDefNode(self, node):
self.visitchildren(node, ('dict', 'metaclass',
'mkw', 'bases', 'class_result'))
- self.flow.mark_assignment(node.target, object_expr_not_none,
+ self.flow.mark_assignment(node.target, node.classobj,
self.env.lookup(node.name))
self.env_stack.append(self.env)
self.env = node.scope