Rahul wrote:
1.def gcd(a,b) expects (int,int)

I presume by this syntax you mean something like: def gcd(a, b) expects (int, int): if b > a: a, b = b, a while a > b > 0: a, b = b, a % b return a

Here the function is not enforcing type checking. The compiler should
only generate warning when someone passes something which is not an int
and should not generate an error.Maybe the person calling the function
knows what he is doing and wants to pass the unexpected type.

But if this is the case, why is it different from?: def gcd(a, b): # expects (int, int) return a * b

2.Another possibility is to let the function decide if the type is not
what it is expecting. Maybe the function recvs some kind of flag which
tells it that the type passed is not what it was expecting. So it can
throw an error if it is really critical.

Again, why make the test at all if you don't want to act on it? assert <boolexp> aborts if it is checked at all, but with __debug__ defined as 1, it passes. Perhaps you are proposing that expects be used in that context.

3.In my post i am not stressing on adding 'expects' as keyword or
something. Only that type should not be enforced and 'expects' makes
this clear.
You need to explain why anyone would want to write expects at all.
If you are expecting the code generation to change, you'd better
enforce, rather than advise, unless you are defining points at which
to do code specialization on types.

--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to