type(d) != type(d.copy()) when type(d).issubclass(dict)
Benjamin Kaplan
benjamin.kaplan at case.edu
Fri Dec 24 17:40:44 EST 2010
On Dec 24, 2010 4:40 PM, "Flávio Lisbôa" <flisboa.costa at gmail.com> wrote:
>>
>> copy, here, is a dict method. It will create a dict.
>> If you really need it, you could try this:
>>
>> import copy
>> class neodict(dict):
>> def copy(self):
>> return copy.copy(self)
>>
>> d = neodict()
>> print type(d)
>> dd = d.copy()
>> print type(dd)
>
>
> One more gotcha to python... OO in python is strange :p
>
> IMO, if i subclass a class, all instance methods from a subclass instance
should work with the subclass. But i'm guessing python doesn't make this
distinction of instance/class methods like some other languages do (unless
one uses annotations, what appears to be not the case with the dict class).
>
This isn't at all unique to Python. You'd get the same results in java or
any other language.
public class Foo {
int a;
public Foo(int a) {
this.a = a;
}
public Foo clone() {
return new Foo(this.a);
}
}
public class Bar extends Foo {
public Bar() {
super(0);
}
}
What type do you think (new Bar()).clone() is going to return?
> Not that it inhibits me on using python in any way, in fact i do use
python for my projects. I'm new to it, and I like some of its features, but
some others are rather strange.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101224/b11d0988/attachment-0001.html>
More information about the Python-list
mailing list