Message199126
=========================================================================
class Boom:
def __dir__(self):
return ['BOOM']
def __getattr__(self, name):
if name =='BOOM':
return 42
return super().__getattr(name)
help(Boom)
=========================================================================
Help on class Boom in module __main__:
class Boom(builtins.object)
| Methods defined here:
|
| __dir__(self)
|
| __getattr__(self, name)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
(END)
=========================================================================
So on an instance there is no problem.
=========================================================================
import inspect
class MetaBoom(type):
def __dir__(cls):
return ['__class__', '__module__', '__name__', 'BOOM']
def __getattr__(self, name):
if name =='BOOM':
return 42
return super().__getattr(name)
def test(self):
print('testing...')
class Boom(metaclass=MetaBoom):
pass
help(Boom())
=========================================================================
Help on Boom in module __main__ object:
<class '__main__.Boom'>
(END)
=========================================================================
Still have problem with metaclasses.
Looking at the result from inspect.classify_class_attrs() we see:
=========================================================================
Attribute(name='BOOM', kind='data', defining_class=None,
object=<object object at 0x7f061f04d200>)
=========================================================================
The defining class for BOOM should be Boom, not None.
With the attached patch, we get:
=========================================================================
Help on Boom in module __main__ object:
class Boom(builtins.object)
| Data and other attributes defined here:
|
| BOOM = 42
(END)
========================================================================= |
|
Date |
User |
Action |
Args |
2013-10-07 03:25:29 | ethan.furman | set | recipients:
+ ethan.furman, arigo, ronaldoussoren, eli.bendersky, eric.snow |
2013-10-07 03:25:29 | ethan.furman | set | messageid: <1381116329.81.0.987690490533.issue16938@psf.upfronthosting.co.za> |
2013-10-07 03:25:29 | ethan.furman | link | issue16938 messages |
2013-10-07 03:25:29 | ethan.furman | create | |
|