[Python-ideas] Modify inspect.getmembers() to return object members in source code order

Cem Karan cfkaran2 at gmail.com
Mon Mar 16 01:29:25 CET 2015


On Mar 15, 2015, at 8:08 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Mon, Mar 16, 2015 at 11:02 AM, Cem Karan <cfkaran2 at gmail.com> wrote:
>> I'd like to suggest that inspect.getmembers() be modified to return elements in the order they are defined in the source code rather than in alphabetical order.
>> 
> 
> I'm not sure that that's really possible, unless you also are
> proposing that OrderedDict be used internally instead of a regular
> dict for all namespaces. That information doesn't exist.

That was what I was afraid of.  

>> As an example, consider generating unit tests for code that really
>> should have had unit tests as the code was written, but didn't
> 
> If I had to solve this problem, I'd parse the source code. Chances are
> your functions/methods follow a straight-forward layout, so you should
> be able to read them and parse them fairly easily.

They are, and I can do so, but I got my hopes up that inspect.getmembers() could be modified easily.  Oh well, such is life.

Thanks,
Cem Karan


More information about the Python-ideas mailing list