[Python-ideas] A user story concerning things knowing their own names

Guido van Rossum guido at python.org
Mon Mar 21 18:04:19 CET 2011

On Sun, Mar 20, 2011 at 10:18 PM, Ian Bicking <ianb at colorstudy.com> wrote:
> On Mon, Mar 21, 2011 at 12:10 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> wrote:
>> Guido van Rossum wrote:
>>> So, apologies if this has been brought up or rejected before, wouldn't
>>> a class decorator work for you?
>> It would work, although it would be a bit less than satisfying,
>> because the property wouldn't be fully self-contained. Some of
>> the plumbing would still be showing, albeit less obtrusively.
> If you forget the decorator (easy to do) the errors could be lots of ugly
> "<PropertyThatMustKnowName at 0x4928394> object has no attribute 'name'" --
> and you could make the error slightly better, but not much because the
> PropertyThatMustKnowName doesn't get a chance to validate itself (since you
> didn't use the decorator and it can't really know that).

It would be easy enough to record the filename and line where the
constructor was called, and report those in the error message.

All in all it does sound like it could be an improvement over having
to pass the name in redundantly, and it has the advantage that it
works today.

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list