Q: Python 2.0 preliminary features?
Jeremy Hylton
jeremy at cnri.reston.va.us
Tue Oct 19 17:16:58 EDT 1999
>>>>> "MS" == skaller <skaller at maxtal.com.au> writes:
MS> Michael Hudson wrote:
>> skaller <skaller at maxtal.com.au> writes:
>> Hold it there a second; you are proposing that knowing that x has
>> a certain type in the expression
>>
>> x = x + "hello"
>>
>> has an impact on inference?
MS> Yes. Rather, the type of x is _deduced_ from the fact that
MS> operator + must be string concatenation in this context, since
MS> the second argument is a string, and thus x must be a string.
I assume you're handling some of the special cases, and I'd be
interested to hear how.
It is easy enough to write a class that will do something when added
to a string. Arbitrary example:
class Foo:
def __init__(self):
self.strings = []
def __add__(self, other):
new = Foo()
new.strings = self.strings[:]
new.strings.append(other)
return new
x = Foo()
x = x + "hello"
I assume you can do some analysis to discover that x *might* be a
class that implements __add__. How specific is your analysis? If you
see a class like Foo, are all bets off about the meaning of x +
"hello"?
The second variation is a library that accepts some object as an
argument and adds "hello" to it. Do you do whole-program analysis to
determine whether any client of the library might pass something other
than a string? What are the implications of that for writing a
generic library?
Jeremy
More information about the Python-list
mailing list