Issue36962
Created on 2019-05-19 03:18 by BTaskaya, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 13414 | closed | BTaskaya, 2019-05-19 03:33 | |
| Messages (9) | |||
|---|---|---|---|
| msg342830 - (view) | Author: Batuhan Taskaya (BTaskaya) * ![]() |
Date: 2019-05-19 03:18 | |
I can't sort the result of iter_modules; >>> import random, pkgutil >>> modules = list(pkgutil.iter_modules(None)) >>> random.shuffle(modules) >>> sorted(modules) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '<' not supported between instances of 'FileFinder' and 'FileFinder' |
|||
| msg342832 - (view) | Author: Batuhan Taskaya (BTaskaya) * ![]() |
Date: 2019-05-19 03:30 | |
I think dataclasses can be used to do it with order, frozen true parameters. Also a __getitem__ is required for doesnt break anything. |
|||
| msg342841 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-05-19 11:37 | |
Unfortunately your change isn't backward compatible with the existing (namedtuple) version. I expect this to fail in the dataclass version: >>> finder, name, ispkg = list(pkgutil.iter_modules(None))[0] And since this is an enhancement, it can only go in to 3.8. And the window is closing for that, so it's more likely to be 3.9, if we decide that backward compatibility isn't important here. |
|||
| msg342843 - (view) | Author: Batuhan Taskaya (BTaskaya) * ![]() |
Date: 2019-05-19 12:25 | |
You're right. I am thinking implementing 4 sequence methods (contains/len/iter/getitem) and set a depraction warning for them. We can remove this methods in next relase On Sun, May 19, 2019, 2:37 PM Eric V. Smith <report@bugs.python.org> wrote: > > Eric V. Smith <eric@trueblade.com> added the comment: > > Unfortunately your change isn't backward compatible with the existing > (namedtuple) version. > > I expect this to fail in the dataclass version: > >>> finder, name, ispkg = list(pkgutil.iter_modules(None))[0] > > And since this is an enhancement, it can only go in to 3.8. And the window > is closing for that, so it's more likely to be 3.9, if we decide that > backward compatibility isn't important here. > > ---------- > nosy: +eric.smith > type: -> enhancement > versions: -Python 3.6, Python 3.7 > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue36962> > _______________________________________ > |
|||
| msg342844 - (view) | Author: Batuhan Taskaya (BTaskaya) * ![]() |
Date: 2019-05-19 12:47 | |
Can you review the PR, i implemented it there. |
|||
| msg342846 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-05-19 13:20 | |
I'm not sure all of this churn is worth it for an unusual use case that can be satisfied by: >>> sorted(pkgutil.iter_modules(None), key=lambda x: (x[1], x[2]) or even: >>> sorted(pkgutil.iter_modules(None), key=operator.itemgetter(1)) (assuming that ispkg doesn't really need to be part of the key) Before reviewing the patch, I suggest you raise the issue on python-dev and get some additional input. |
|||
| msg342849 - (view) | Author: Berker Peksag (berker.peksag) * ![]() |
Date: 2019-05-19 13:37 | |
I agree with Eric that this use case can be easily covered by using sorted(..., key=...). I suggest closing this as 'rejected'. |
|||
| msg342852 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-05-19 13:50 | |
Dataclasses are even more heavyweight than namedtuples. I am not sure that they should be used in the stdlib now. Especially in this case. I think the common use of iter_modules() is immediate unpacking of the yielded tuple:
for importer, modname, ispkg in pkgutil.iter_modules():
...
Your change breaks it.
I agree with Eric and Berker that this issue should be closed.
|
|||
| msg342867 - (view) | Author: Eric V. Smith (eric.smith) * ![]() |
Date: 2019-05-19 18:23 | |
I agree. Sorry, BTaskaya, but I just don't think the benefit of this change is worth the disruption. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:15 | admin | set | github: 81143 |
| 2019-05-19 18:23:35 | eric.smith | set | status: open -> closed resolution: wont fix messages: + msg342867 stage: patch review -> resolved |
| 2019-05-19 13:50:07 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg342852 |
| 2019-05-19 13:37:57 | berker.peksag | set | nosy:
+ berker.peksag messages: + msg342849 |
| 2019-05-19 13:20:46 | eric.smith | set | messages: + msg342846 |
| 2019-05-19 12:47:57 | BTaskaya | set | messages: + msg342844 |
| 2019-05-19 12:25:25 | BTaskaya | set | messages: + msg342843 |
| 2019-05-19 11:37:56 | eric.smith | set | versions:
- Python 3.6, Python 3.7 nosy: + eric.smith messages: + msg342841 type: enhancement |
| 2019-05-19 03:33:00 | BTaskaya | set | keywords:
+ patch stage: patch review pull_requests: + pull_request13325 |
| 2019-05-19 03:30:36 | BTaskaya | set | messages: + msg342832 |
| 2019-05-19 03:18:37 | BTaskaya | create | |
