[PEAK] Config like metadata
Radek Kanovsky
rk at dat.cz
Wed Dec 15 11:54:39 EST 2004
On Tue, Dec 14, 2004 at 01:33:38PM -0500, Phillip J. Eby wrote:
Thanks for advise. The solution with generic function is more elegant.
My very first draft was four times longer (slightly overdesigned).
> >Current limitations:
> >
> > * metadata registry is global and is not thread-safe
> > * works only with new-style classes for now
> > * it would be better to raise exception when metadata is not found
> > instead of returning NOT_FOUND (if default is not given)
> > * registry allows redeclare metadata after they have been looked up
>
> By the way, the generic function solution I proposed also has a (sort-of)
> fix for the last item, too. If you declare two 'Title' objects as metadata
> for the same class and attribute, you'll get an AmbiguousMethod error at
> the point of invocation.
I was not sure whether metadata redeclaration should be denied.
> I'm thinking I'll probably incorporate something like this into PEAK, at
> least once I've put IsSubclass into the dispatch package.
The last version of IsSubclass seems to be functional although I don't
use it very intensively.
> I would probably distinguish between class metadata and attribute
> metadata, though, because class metadata ('None' in your examples)
> is different from wildcard attribute metadata ('"*"' in your
> examples), and the class metadata shouldn't really be going through
> 'declareAttribute'. Instead, the binding package should probably
> include 'declareClassMetadata' or something like that.
>
> Hm. Maybe 'declareAttributes' should actually be 'declareMetadata',
> and take positional arguments for class metadata, and the 'metadata'
> advisor could do the same thing. So, you could have, e.g.:
>
> class Foo(model.Element): binding.metadata( PrimaryKey('x','y') )
>
> in order to declare class-level metadata.
I have deleted some lines from 'metadata' module for keeping example
simple. Modified 'metadata' advisor was such case.
Note that there is also 'declareAttributes' (plural) method in
peak.binding, so 'declareMetadata' would be more convenient name.
> One nice thing about this approach is that it means there's no need to
> write your own class advisors in order to get class-level metadata.
`security.allow' and its friends could be deprecated.
RadekK
More information about the PEAK
mailing list