Ethan Furman added the comment:

=========================================================================
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)
=========================================================================

----------
assignee:  -> ethan.furman
keywords: +patch
priority: low -> normal
stage: test needed -> patch review
versions:  -Python 2.7
Added file: http://bugs.python.org/file31982/issue16938.stoneleaf.01.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16938>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to