[IronPython] Lambdas, properties and namespace leakage
Michael Foord
michael.foord at resolversystems.com
Fri Jun 1 17:05:40 CEST 2007
Hello all,
Another fun one. If you use 'property' to wrap a lambda in a class
namespace then an extra name leaks into the class namespace (which
confused our documentation system).
CPython:
>>> class X(object):
... p2 = property(lambda self: 34)
...
>>> dir(X)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash_
_', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__',
'__repr_
_', '__setattr__', '__str__', '__weakref__', 'p2']
Amongst all the detritus you can see 'p2' nestled there at the end.
IronPython:
>>> class X(object):
... p2 = property(lambda self: 34)
...
>>> dir(X)
['<lambda$0>', '__class__', '__dict__', '__doc__', '__init__',
'__module__', '__
new__', '__reduce__', '__reduce_ex__', '__repr__', '__weakref__', 'p2']
See the weird first entry! Shouldn't be there...
Thanks
Michael
--
Michael Foord
Resolver Systems
michael.foord at resolversystems.com
Office address: 17a Clerkenwell Road, London EC1M 5RD, UK
Registered address: 843 Finchley Road, London NW11 8NA, UK
Resolver Systems Limited is registered in England and Wales as company number 5467329.
VAT No. GB 893 5643 79
More information about the Ironpython-users
mailing list