Message129024
| Author |
Trundle |
| Recipients |
Trundle, daniel.urban, michael.foord, segfaulthunter |
| Date |
2011年02月22日.01:40:40 |
| SpamBayes Score |
5.589423e-08 |
| Marked as misclassified |
No |
| Message-id |
<AANLkTi=nSh2==QFw8KAPJ-ePro4--xrAic6ux=CdW6Zx@mail.gmail.com> |
| In-reply-to |
<1298288178.57.0.753216281337.issue11133@psf.upfronthosting.co.za> |
| Content |
> The patch is not sufficient - instances may have a class member "__dict__" whilst still having an instance __dict__.
Sure, but I don't think there is a way how you can access the instance
__dict__ in that case inside Python code. At least I can't think of
one.
>Alternatively the "__dict__" property may be provided by a base class and so not available in "type(obj).__dict__" but still be provided by a property.
>
> I don't think there is any general way to tell whether fetching obj.__dict__ will get an instance dictionary or fetch a "__dict__" member from the class or a base-class... (Hence the documented exception.)
Why not? ``obj.__dict__`` will fetch the instance dictionary iff there
is no class attribute "__dict__" in any of the base classes. In the
patch,``type.__dict__["__dict__"].__get__()`` is used to get (without
any doubt) the class dictionary. By looking inside that dictionary, we
can now tell whether "__dict__" is overwritten: If it isn't
overwritten, the dictionary either doesn't have a "__dict__" entry at
all or the value is a getset_descriptor. So we just need to iterate
over a type's mro, look inside each entries' dictionary and stop when
a "__dict__" entry is found. |
|