[Python-3000] Type parameterization
Jim Jewett
jimjjewett at gmail.com
Sat May 20 01:18:13 CEST 2006
On 5/19/06, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote:
> "Jim Jewett" <jimjjewett at gmail.com> writes:
>
> > __getitem__ on a dictionary instance happens to be defined.
> > __getitem__ on the dict class happens not to be defined.
>
> I wouldn't be so sure.
>
> >>> dict.__getitem__
> <method '__getitem__' of 'dict' objects>
> >>> dict.__getitem__({'one':1}, 'one')
> 1
I should have been more precise.
On a dictionary instance, __getitem__ wil be found (in the definition
of the class dict)
On a type instance, such as dict itself, __getitem__ will not be found
(in the definition of the (meta)class type)
If the implementation of [] ends up doing the moral equivalent of
(self.__getitem__(arg) if not isintance(self, type) else
self.__parameterization__(arg))
then we're running into problems with
If the implementation is hard to explain, it's a bad idea.
-jJ
More information about the Python-3000
mailing list