Decorator syntax (was Re: PEP 318 - PyFIT comments)

John Roth newsgroups at jhrothjr.com
Thu Aug 5 15:06:01 CEST 2004


"Michael Hudson" <mwh at python.net> wrote in message
news:m3pt65g4hb.fsf at pc150.maths.bris.ac.uk...
> "John Roth" <newsgroups at jhrothjr.com> writes:
>
> > "Bruce Eckel" <BruceEckel at MailBlocks.com> wrote in message
> > news:mailman.1168.1091667628.5135.python-list at python.org...
> > > I'll weigh in a little on this one.
> > >
> > > This is very similar to attributes/metadata in Java J2SE 5 and in C#.
> > > The thing is, metadata is a little bit weird; it's intentionally
> > > outside of the domain of the 'normal' programming language, because it
> > > expresses things that you can't or shouldn't within the normal
> > > programming language.
>
> Except, of course, this is Python so there isn't any such thing as
> metadata, really.  Objects all the way down.
>
> > > So you _do_ need an escape mechanism. And it also takes a little
> > > bit of getting used to; it's orthogonal to what you normally think
> > > of as a language feature. But the potential for metadata features,
> > > at least in Java, is very powerful.
> >
> > I'd be a lot happier if it was, in fact, a general metadata
> > facility. Unfortunately, it only seems to work on functions
> > (methods), and for what I'm working on I need metadata for
> > properties and fields as well, that is, any identifier that you can
> > bind an object to.
>
> Well, that would be because that's impossible :-)

I wish you'd have told me that before I did it. As I said in
a prior post, I had to put a general metadata facility into
PyFIT, and it's working quite nicely, thank you.

What I did was put a dictionary with a known name (_typeDict)
into the class, and stick the metadata in there. It's nowhere near
as convenient as being able to directly associate it with the
needed bindings, but it does serve my needs in that particular
package.

> Where would you
> attach the data in:
>
> class C(object):
>     @funky
>     i = 0
>
> ?
>
> You can't attach it to 'i' -- that's just a string.  '0' is just an
> integer.  The class doesn't exist at the time the body is executed.

Two of which are exactly the points I mentioned. The third
is piffle. If the implementer wanted to do it, there is no reason
why it couldn't be done.

>
> What you can do (today) of course is stuff like:
>
> class C(object):
>     i = MagicProperty(int, default=0)
>
> or something -- which obviously leaves ample space for metadata in the
> argument list -- but that can be painful, I grant.
>
> What kind of metadata do you want?

Type and other declaration information for any identifiers
that will be referenced in the FIT tests. Other information
includes things like precision for floating point numbers,
strings that are accepted as "true" or "false" for booleans,
the subtype for lists and tuples, references to custom
type adapters and other stuff.

> (I have to admit I read your first post on this thread a bit like
> "this hammer doesn't do a very good job of screwing in screws" :-)

Well, that's basically what it said, after all. I was trying to find
something I could use the facility for. I can always dream up
ways someone else could use it, but I've found out after long
and painful experiance that if I'm not the developer in question,
at best it's a futile exercise.

That was basically my comment about ctypes. AMK's
blog entry referenced the ctype's documentation page,
which didn't tell me anything about what Thomas Heller
would do with it in the context of that package, and I'm
not enough of an expert on ctypes to see it myself.

John Roth
>
> Cheers,
> mwh
>
> -- 
>   It is time-consuming to produce high-quality software. However,
>   that should not alone be a reason to give up the high standards
>   of Python development.              -- Martin von Loewis, python-dev





More information about the Python-list mailing list