[Python-Dev] inspect() and dir()

Nick Coghlan ncoghlan at gmail.com
Thu Oct 10 11:25:41 CEST 2013


On 10 Oct 2013 14:32, "Ethan Furman" <ethan at stoneleaf.us> wrote:
>
> On 10/09/2013 03:36 PM, Nick Coghlan wrote:
>
>> On 10 Oct 2013 08:07, "Ethan Furman" wrote:
>>>
>>> On 10/09/2013 02:46 PM, Nick Coghlan wrote:
>>>>
>>>> On 10 Oct 2013 03:39, "Ethan Furman" wrote:
>>>>>
>>>>>
>>>>> My apologies.  I am actually talking about the module.  I meant
>>>>>  inspect.get_members() and inspect.classify_class_attrs(), which,
>>>>>  as near as I can tell, are the only two functions in inspect that
>>>>>  attempt to retrieve/look at all of an object's attributes.
>>>>
>>>>
>>>> Those have to depend on __dir__ so classes (especially proxies)
>>>>  can accurately report *extra* dynamically accessible names.
>>>
>>>
>>> Indeed, my rough idea is to use the results of the new dir() and
>>>  combining that with the results of the old dir().  The use case
>>>  being that some classes *ahem* Enum *ahem* may report *less* than
>>>  is actually available, but introspection should reveal whatever is
>>>  there even if dir() is not reporting it.
>>
>>
>> Not necessarily. For autocompletion, for example, you probably
>> only want the public stuff. That's why I'm inclined to suggest
>>  the existing functions should continue to only report advertised
>> attributes, with a separate introspection API that tries harder
>>  to find all accessible attributes (potentially including those
>> from the metaclass). That way users can choose the one most
>>  appropriate to their use case, as well as being able to use the
>>  latter to help test custom dir support.
>
>
> That makes sense.
>
> So what should the new functions be called?  get_all_members and
classify_all_class_attrs ?

Yeah, those work for me. The only way they should miss anything is if
attribute lookup is customised to offer extra dynamic attributes without
implementing custom dir support.

Cheers,
Nick.

>
>
> --
> ~Ethan~
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131010/92749f5c/attachment.html>


More information about the Python-Dev mailing list