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

Cem Karan cfkaran2 at gmail.com
Mon Mar 16 01:39:59 CET 2015


On Mar 15, 2015, at 8:13 PM, Nathaniel Smith <njs at pobox.com> wrote:

> Line number information is retained, so you could sort by that. In fact you could do this without modifying inspect.getmembers...

You mean via a combinations of inspect.getmembers() and inspect.getsourcelines()?  Yeah, I think that could work.  I'll have to play around a bit to be sure I've got the hang of it, but I'm going to provisionally withdraw my suggestion about changing getmembers().  Thank you Nathaniel!

> -n
> 
> On Mar 15, 2015 5:09 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.
> 
> > 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.
> 
> ChrisA

Thanks,
Cem Karan


More information about the Python-ideas mailing list