PEP? context overloading: if wants(type): ...

Jim Dennis jimd at
Mon Aug 6 09:23:12 CEST 2001

 I'm not qualified to formally champion a PEP, but I'd 
 like to raise the question here to see if it's of interest.

 One feature that I find interesting about PERL is it's 
 "context sensitivity."  (By contrast the inability to overload
 a function on *return* type is a limitation of C++ that I find
 irritating and unnecessary).  

 I'd propose, if I felt qualified to do so, to offer a "wants()"
 or builtin that would allow a method to determine the desired
 return type or "context" of an invocation.

 So the use could look like:

	import types
 	if wants(IntType):
		return n
	elif wants(TupleType):
		return (n1,n2)
	elif wants(StringType):	
		return `n`
	elif wants(VoidType):		# NoneType?

 What am I missing about this?  What would it hurt?

More information about the Python-list mailing list