def declare_python_arg(self, env, arg):
if arg:
- entry = env.declare_var(arg.name,
- PyrexTypes.py_object_type, arg.pos)
+ if env.directives['infer_types'] != 'none':
+ type = PyrexTypes.unspecified_type
+ else:
+ type = py_object_type
+ entry = env.declare_var(arg.name, type, arg.pos)
entry.used = 1
entry.init = "0"
entry.init_to_none = 0
import ExprNodes
+import Nodes
+import Builtin
import PyrexTypes
from PyrexTypes import py_object_type, unspecified_type, spanning_type
from Visitor import CythonTransform
class MarkAssignments(CythonTransform):
def mark_assignment(self, lhs, rhs):
- if isinstance(lhs, ExprNodes.NameNode):
+ if isinstance(lhs, (ExprNodes.NameNode, Nodes.PyArgDeclNode)):
if lhs.entry is None:
# TODO: This shouldn't happen...
# It looks like comprehension loop targets are not declared soon enough.
self.visitchildren(node)
return node
+ def visit_DefNode(self, node):
+ # use fake expressions with the right result type
+ if node.star_arg:
+ self.mark_assignment(
+ node.star_arg, TypedExprNode(Builtin.tuple_type))
+ if node.starstar_arg:
+ self.mark_assignment(
+ node.starstar_arg, TypedExprNode(Builtin.dict_type))
+ self.visitchildren(node)
+ return node
+
class PyObjectTypeInferer:
"""
assert typeof(b) == "Python object", typeof(c)
c = MyType()
assert typeof(c) == "MyType", typeof(c)
+
+@infer_types('safe')
+def args_tuple_keywords(*args, **kwargs):
+ """
+ >>> args_tuple_keywords(1,2,3, a=1, b=2)
+ """
+ assert typeof(args) == "tuple object", typeof(args)
+ assert typeof(kwargs) == "dict object", typeof(kwargs)