laike9m / pdir2

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

@staticmethod shouldn't be in "descriptor" category #38

Closed laike9m closed 5 years ago

laike9m commented 6 years ago
>>> pdir(pdir)
abstract class:
    __subclasshook__
attribute access:
    __delattr__, __dir__, __getattribute__, __setattr__
class customization:
    __init_subclass__
emulating container:
    __getitem__, __len__
object customization:
    __format__, __hash__, __init__, __new__, __repr__, __sizeof__, __str__
other:
    repl_type
pickle:
    __reduce__, __reduce_ex__
rich comparison:
    __eq__, __ge__, __gt__, __le__, __lt__, __ne__
special attribute:
    __class__, __dict__, __doc__, __module__, __weakref__
descriptor:
    get_category: class staticmethod with getter, staticmethod(function) -> method
    repr_str: @property with getter
function:
    _PrettyDir__getattr_wrapper: A wrapper around getattr(), handling some exceptions.
    _PrettyDir__inspect_category:
    index:
    s: Search for names that match some pattern.
    search: Search for names that match some pattern.

Though it's actually a descriptor, (I assume) people would more like to see it marked as "staticmethod".

willowj commented 6 years ago

Static Methods and Class Methods are kinds of Non-data descriptors . https://docs.python.org/2/howto/descriptor.html#static-methods-and-class-methods

laike9m commented 6 years ago

@willowj I know, but I care about which representation helps user the most. 99% people don't know what "Non-data descriptors" is, a "staticmethod" label definitely tells people what they need to know.

willowj commented 6 years ago

@laike9m As for behaviour, actually stacticmehod and classmethod act as fucntions, but they are implemented by Non-data descriptors. These two categorizations appeal to diffrent users .

Simple users maybe just care about the behaviour, anyway most pythoners will encouter descriptors soon or later, if they want to know more about python. And this is a good chance to take some minutes to know what descriptor is.

Most important of all. standalone lablel will be under a big risk, that it may mislead users over this fact. Its not worthwhile,

So, i deem that existed category with labeling "staticmethod" or "classmethod" is a fine solution for trade-off.

willowj commented 6 years ago

Maybe type notation is a better method to banlance this

laike9m commented 6 years ago

By "type notation" do you mean function signature?

Also I don't really understand why you think this label will mislead users.

In my mind, people use dir because they want to know what's in the inspected object, which is a shortcut compared to reading source code. @staticmethod is what they see if they do read the source code, and that's probably the information I want pdir2 to provide. pdir2 does not aim to help people learn Python in anyway.