Issue33910
Created on 2018-06-20 08:40 by mbussonn, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 7819 | closed | mbussonn, 2018-06-20 08:52 | |
| Messages (3) | |||
|---|---|---|---|
| msg320037 - (view) | Author: Matthias Bussonnier (mbussonn) * | Date: 2018-06-20 08:40 | |
Docs of random.Random always refer to it with Random([seed]) (`lib/random.py`), tough the parameter is actually named `x` making it : - non obvious what it does. - hard to search for. - hard to remember when using kwargs. Obviously changing the name is a change in API, though I doubt it is used much as a kwarg... I suggest renaming it to `seed=`, deprecating but still allowing the usage of `x=` for now, until proper removal of `x=` |
|||
| msg320080 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2018-06-20 14:37 | |
Thanks for the suggestion. You are right about *x*, *n*, or *a* being the best possible parameter name. That said, it doesn't seem to have ever caused a problem in practice (this API has been around for a very long time), so I'm reluctant to create any disruption (breaking existing code) with a deprecation for something with so little benefit (this docstrings are very clear about what the parameter means). There is also the matter of possible confusion with the seed() method which uses the *a* or the internal _randommodule.c that uses *n* but doesn't allow keyword arguments). I think the lesson here is that parameter names should be carefully considered when a new API is created rather than decades after its release into the wild. |
|||
| msg320145 - (view) | Author: Matthias Bussonnier (mbussonn) * | Date: 2018-06-21 09:24 | |
Thanks @rhettinger, this is a perfectly valid position, and one of the respons I was expecting. > That said, it doesn't seem to have ever caused a problem in practice (this API has been around for a very long time) I have myself not found a lot of usage of `random.Random(x=123)` though I can't say what the lack of occurences is due to. If I have the choice between - Random(123) - Random(x=123) - Random(seed=123) I definitively find `Random(x=123)` the least readable. I can guess what `Random(123)` means, `Random(seed=123)` is self-explanatory, `Random(x=123)` will make me doubt what this means. So you might say no one as reported problem because no one is using it... Yes `x` is explained in the docstring, but that's still requires reading the docstring and reaching for it. As some tab completion engine show functions signatures I want to argue that good parameter names could thus make a difference. Thanks again for you quick response I'm going to close corresponding PRs. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:01 | admin | set | github: 78091 |
| 2018-06-21 09:24:36 | mbussonn | set | messages: + msg320145 |
| 2018-06-20 14:37:37 | rhettinger | set | status: open -> closed resolution: rejected messages: + msg320080 stage: patch review -> resolved |
| 2018-06-20 09:25:30 | serhiy.storchaka | set | assignee: rhettinger nosy: + rhettinger |
| 2018-06-20 08:52:37 | mbussonn | set | keywords:
+ patch stage: patch review pull_requests: + pull_request7427 |
| 2018-06-20 08:40:15 | mbussonn | create | |
