Commit aee8b65a authored by Stefan Behnel's avatar Stefan Behnel

properly integrate Python class nodes into type inference

parent 9b566f8e
...@@ -7163,14 +7163,18 @@ class ClassNode(ExprNode, ModuleNameMixin): ...@@ -7163,14 +7163,18 @@ class ClassNode(ExprNode, ModuleNameMixin):
# module_name EncodedString Name of defining module # module_name EncodedString Name of defining module
subexprs = ['bases', 'doc'] 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): def analyse_types(self, env):
self.bases = self.bases.analyse_types(env) self.bases = self.bases.analyse_types(env)
if self.doc: if self.doc:
self.doc = self.doc.analyse_types(env) self.doc = self.doc.analyse_types(env)
self.doc = self.doc.coerce_to_pyobject(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")) env.use_utility_code(UtilityCode.load_cached("CreateClass", "ObjectHandling.c"))
return self return self
...@@ -7215,10 +7219,14 @@ class Py3ClassNode(ExprNode): ...@@ -7215,10 +7219,14 @@ class Py3ClassNode(ExprNode):
# allow_py2_metaclass bool should look for Py2 metaclass # allow_py2_metaclass bool should look for Py2 metaclass
subexprs = [] 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): def analyse_types(self, env):
self.type = py_object_type
self.is_temp = 1
return self return self
def may_be_none(self): def may_be_none(self):
......
...@@ -5,8 +5,7 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object, ...@@ -5,8 +5,7 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
Builtin=object, InternalError=object, Builtin=object, InternalError=object,
error=object, warning=object, error=object, warning=object,
py_object_type=object, unspecified_type=object, py_object_type=object, unspecified_type=object,
object_expr=object, object_expr_not_none=object, object_expr=object, fake_rhs_expr=object, TypedExprNode=object)
fake_rhs_expr=object, TypedExprNode=object)
from . import Builtin from . import Builtin
from . import ExprNodes from . import ExprNodes
...@@ -29,7 +28,6 @@ class TypedExprNode(ExprNodes.ExprNode): ...@@ -29,7 +28,6 @@ class TypedExprNode(ExprNodes.ExprNode):
return self._may_be_none != False return self._may_be_none != False
object_expr = TypedExprNode(py_object_type, may_be_none=True) 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 to silence "unused variable" warning
fake_rhs_expr = TypedExprNode(unspecified_type) fake_rhs_expr = TypedExprNode(unspecified_type)
...@@ -1287,7 +1285,7 @@ class ControlFlowAnalysis(CythonTransform): ...@@ -1287,7 +1285,7 @@ class ControlFlowAnalysis(CythonTransform):
def visit_PyClassDefNode(self, node): def visit_PyClassDefNode(self, node):
self.visitchildren(node, ('dict', 'metaclass', self.visitchildren(node, ('dict', 'metaclass',
'mkw', 'bases', 'class_result')) '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.lookup(node.name))
self.env_stack.append(self.env) self.env_stack.append(self.env)
self.env = node.scope self.env = node.scope
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment