Patches item #1591665, was opened at 2006-11-07 07:52
Message generated for change (Comment added) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1591665&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: ganges master (gangesmaster)
Assigned to: Nobody/Anonymous (nobody)
Summary: adding __dir__

Initial Comment:
in accordance with 
http://mail.python.org/pipermail/python-dev/2006-November/069865.html

i've written a patch that allows objects to define their
own introspection mechanisms, by providing __dir__.
with this patch:
* dir() returns the locals. this is done in builtin_dir()
* dir(obj) returns the attributes of obj, 
by invoking PyObject_Dir()
* if obj->ob_type has "__dir__", it is used. 
note that it must return a list!
* otherwise, use default the mechanism of collecting 
attributes
* for module objects, return __dict__.keys()
* for type objects, return __dict__.keys() +
dir(obj.__base__)
* for all other objects, return __dict__.keys() + 
__members__ + __methods__ + dir(obj.__class__)
* builtin_dir takes care of sorting the list

----------------------------------------------------------------------

>Comment By: Nick Coghlan (ncoghlan)
Date: 2006-11-07 08:52

Message:
Logged In: YES 
user_id=1038590

The retrieval of locals on a NULL argument and the sorting
step need to move back inside PyObject_Dir to avoid changing
the C API.

If the standard library's current C API tests didn't break
on this version of the patch, then the final version of the
patch should include enhanced tests for PyObject_Dir that
pass both before and after the patch is applied to PyObject_Dir.

Other than that, I didn't see any major problems on reading
the code (i.e. refcounts and error handling looked pretty
reasonable). I haven't actually run it though.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1591665&group_id=5470
_______________________________________________
Patches mailing list
[email protected]
http://mail.python.org/mailman/listinfo/patches

Reply via email to