[Python-Dev] Re: Sets: elt in dict, lst.include

Skip Montanaro skip@mojam.com (Skip Montanaro)
2001年1月31日 16:27:38 -0600 (CST)


>>>>> "Tim" == Tim Peters <tim.one@home.com> writes:

 >> (Obviously, lists *do* understand __getitem__ at some level. Why
 >> isn't it exposed in the method table?)
 Tim> The old type/class split: list is a type, and types spell their
 Tim> "method tables" in ways that have little in common with how classes
 Tim> do it.
The problem that rolls around in the back of my mind from time-to-time is
that since Python doesn't currently support interfaces, checking for
specific methods seems to be the only reasonable way to determine if a
object does what you want or not.
What would break if we decided to simply add __getitem__ (and other sequence
methods) to list object's method table? Would they foul something up or
would simply sit around quietly waiting for hasattr to notice them?
Skip

AltStyle によって変換されたページ (->オリジナル) /