[Python-ideas] anonymous object support
Mike Graham
mikegraham at gmail.com
Fri Aug 5 22:49:55 CEST 2011
2011/8/5 dag.odenhall at gmail.com <dag.odenhall at gmail.com>
> 2011/8/4 Matej Lieskovský <lieskovsky.matej at googlemail.com>:
> > ...
> > perhaps a "namespace" statement would do, behaving somewhat like this:
> > namespace MyObject:
> > statements
> > is equivalent to:
> > class MyClass(object):
> > statements
> > MyObject = MyClass()
> > MyClass = None
> > ...
As a somewhat off-topic remark, this could already be accomplished
with metaclasses. We could write
def namespace(name, bases, d):
return type(name, bases, d)()
trivially then use it like
class MyObject(metaclass=namespace):
statements
which is really quite slick conceptually. Syntactically, this is ugly
and the terminology we use seems to confuse people.
If Python was to introduce new syntax for this, it would ideally solve
the broader problem here.
Mike
More information about the Python-ideas
mailing list