[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-10-01 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type:  -> enhancement
versions: +Python 3.11 -Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-27 Thread Cristobal Riaga

Cristobal Riaga  added the comment:

That worked , thank you for your time and answer.
I will keep working on PyAPIReference.
Also I will close the pull request I created on GitHub.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Ah, if you only need a module, then just use its __dict__ (or vars()).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-27 Thread Cristobal Riaga


Cristobal Riaga  added the comment:

I'm don't really need inherit order, neither built-in members.
e.g.:
```py
a = 3 # First

class B: # Second
pass

def foo(): # Third
pass

```
Or in a more complex module:
```py
class A: # First
pass

class B: # Second
pass

class C(A, B): # Third
pass
```
The order should be:
- A (class)
- B (class)
- C (class): inherited from A and B.

Here is the link to the script I'm using to inspect a module: 
https://github.com/Patitotective/PyAPIReference/blob/main/PyAPIReference/inspect_object.py.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It depends on what you want to get. In general, it is difficult if interpret 
your request literally. For example, if you define class A in module a, class B 
in module b, and class C which inherits from classes A and B in module c, then 
what members of C are defined first: inherited from A or inherited from B? Oh, 
and some members can be defined in a metaclass of A, B or C. And what order of 
members inherited from the object class or other builtin classes? And what to 
do with members excluded from __dir__()? And dynamic members provided by 
__getattr__() or __getattribute__()? You need to specify in more detail what 
you want to get a meaningful answer. It may be that you actually do not need 
all these details and can just look in type's dicts in the mro order.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-26 Thread Cristobal Riaga


Cristobal Riaga  added the comment:

So there is no way to get members in the order you defined them?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-26 Thread Cristobal Riaga


Cristobal Riaga  added the comment:

So there is no way to get the members in order?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-25 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

But you will not get them in creation order, even if omit the final sort, 
because:

1. dir() returns names sorted alphabetically, not in order of creation.
2. Dynamic class attributes are added at the end, and inherited attributes 
follow attributes defined in that class.

So adding this parameter will not help you.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-25 Thread Cristobal Riaga


Cristobal Riaga  added the comment:

Added sort_result parameter (bool=True) on getmembers function inside 
Lib/inspect.py, that, as it name says, allows you to getmembers result without 
sorting it.
I'm needed of this and it seems impossible to achieve because of 367 line:

results.sort(key=lambda pair: pair[0])

Any other solution is very welcomed.

(I need it because I'm working on an API Reference creator and I think it would 
be better if it the members are ordered in the same order you define them.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45288] Inspect - Added sort_result parameter on getmembers function.

2021-09-25 Thread Cristobal Riaga


New submission from Cristobal Riaga :

Added `sort_result` parameter (`bool=True`)  on `getmembers` function inside 
`Lib/inspect.py`, that, as it name says, allows you to `getmembers` result 
without sorting it.
I'm needed of this and it seems impossible to achieve because of [`367` 
line](https://github.com/python/cpython/blob/3.9/Lib/inspect.py#L367): 
```py
results.sort(key=lambda pair: pair[0])
```
Any other solution is very welcomed.

(I need it because I'm working on an [API Reference 
creator](https://github.com/Patitotective/PyAPIReference) and I think it would 
be better if it the members are ordered in the same order you define them.)

--
components: Library (Lib)
messages: 402626
nosy: Patitotective
priority: normal
pull_requests: 26947
severity: normal
status: open
title: Inspect - Added sort_result parameter on getmembers function.
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com