laike9m / pdir2

Pretty dir() printing with joy:beer:
MIT License
1.33k stars 47 forks source link

Fix __slots__ bug (#44) #45

Closed liwt31 closed 5 years ago

liwt31 commented 5 years ago

fix the bug by another try/except and add a test for it.

laike9m commented 5 years ago

Thanks for the fix, I neglected the missing __dict__ issue. There are a few problems in this commit, see comments below.

liwt31 commented 5 years ago

I'm sorry but I can't see any comments. GitHub has some issue yesterday, maybe your comment is rolled back?

laike9m commented 5 years ago

Cause I didn't submit them yesterday.

liwt31 commented 5 years ago

I've tried to implement a version based on the idea of making __slots__ a property of attributes, Here's an example:

>>> class A:
...     __slots__ = ['__mul__', '__hash__', 'a', 'b']
>>> pdir(A())
special attribute:
    __class__, __doc__, __module__, __slots__
abstract class:
    __subclasshook__
arithmetic:
    __mul__(slotted)
object customization:
    __format__, __hash__(slotted), __init__, __new__, __repr__, __sizeof__, __str__
rich comparison:
    __eq__, __ge__, __gt__, __le__, __lt__, __ne__
attribute access:
    __delattr__, __dir__, __getattribute__, __setattr__
class customization:
    __init_subclass__
pickle:
    __reduce__, __reduce_ex__
descriptor:
    a(slotted): class member_descriptor with getter, setter, deleter
    b(slotted): class member_descriptor with getter, setter, deleter
laike9m commented 5 years ago

LGTM. Thanks for the great work and quick responses!

liwt31 commented 5 years ago

And thanks for your comments and advice! It's a pleasure having discussions with you.