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

Chris Angelico rosuav at gmail.com
Mon Mar 16 01:08:55 CET 2015


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


More information about the Python-ideas mailing list