Are decorators really that different from metaclasses...
Steven Bethard
steven.bethard at gmail.com
Wed Aug 25 12:13:25 EDT 2004
Paul Morrow <pm_mon <at> yahoo.com> writes:
> Steven Bethard wrote:
> > Are you trying to say that "metadata" is the same thing as "operator
shortcut"?
>
> Not exactly, but it would include defining those.
Ahh. Well I at least sort of see where you're going with this now, thanks.
It's probably notable that I could write my example in two ways:
class Identity:
def get(self, x):
return x
__getitem__ = get
class Identity:
def __getitem__(self, x):
return x
get = __getitem__
I think I could agree that the use of things like __getitem__ can indicate
some metadata about the class, but I'd note that that is not all they do. In
the example here, __getitem__ defines a function that can be used like any
other function. At the same time, because it's *named* __getitem__, we get
some metadata about the function.
Using the same logic, I should expect that in something like:
def baz():
__foo__ = "bar"
# body of baz
__foo__ would be a string, and could be used like any other string. At the
same time, because it was *named* __foo__, we would get some metadata about
the string.
So I guess my point is that, while the *name* might give us some metadata, I'm
not convinced that the *use* is in any sense metadata.
STeve
More information about the Python-list
mailing list