make CallNode a little smarter about when the return value can be None
authorStefan Behnel <stefan_ml@behnel.de>
Mon, 16 Dec 2013 18:08:53 +0000 (19:08 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Mon, 16 Dec 2013 18:08:53 +0000 (19:08 +0100)
Cython/Compiler/ExprNodes.py

index 4f75668..0185019 100644 (file)
@@ -4230,6 +4230,14 @@ class CallNode(ExprNode):
     def may_be_none(self):
         if self.may_return_none is not None:
             return self.may_return_none
+        func_type = self.function.type
+        if func_type is type_type and self.function.is_name:
+            entry = self.function.entry
+            if entry.type.is_extension_type:
+                return False
+            if (entry.type.is_builtin_type and
+                    entry.name in Builtin.types_that_construct_their_instance):
+                return False
         return ExprNode.may_be_none(self)
 
     def analyse_as_type_constructor(self, env):