msg294305 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-05-24 01:01 |
The __slots__ documentation in the datamodel needs improvement.
For example:
> When inheriting from a class without __slots__, the __dict__ attribute of that class will always be accessible, so a __slots__ definition in the subclass is meaningless.
The __slots__ definition for such a subclass is not meaningless: other slots declared will still be used, and the __dict__ will not be instantiated unless it is looked for (although this may be an implementation detail).
> The action of a __slots__ declaration is limited to the class where it is defined. As a result, subclasses will have a __dict__ unless they also define __slots__ (which must only contain names of any additional slots).
That's not quite right either. The action of a __slots__ declaration is not entirely limited to the class where it is defined. They can have implications for multiple inheritance, and child classes will have access to those slots.
I have some changes I'd like to make to the entire section on __slots__, and I'll be providing a pull request soon.
|
msg294310 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-05-24 02:25 |
I've been working on this section quite a lot, trying to improve the flow of content (which in the prior revision is a bit of a mish-mash of information in the "Notes on using __slots__ section") - I intend to move some of that information into the exposition/introduction.
I have also been reviewing my changes and actively working on it with a volunteer at the PyCon sprints, Joshua Goldin. Will submit a pull request soon, tonight or tomorrow morning.
|
msg294429 - (view) |
Author: Raymond Hettinger (rhettinger) * |
Date: 2017-05-25 03:50 |
As much as possible, please stick with the existing terse style of the data model docs. They tend to be concise, direct, and very light on examples. They don't serve as a tutorial, faq, or cover programming patterns or advice.
Looking at the PR, I don't think most of these changes should be made.
|
msg294515 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-05-25 21:58 |
I created a new PR based on rhettinger's feedback (which on consideration was quite correct) with a fresh branch from master.
Terseness is retained, and I think this revision makes the documentation more correct and complete. The rewording makes the behavior more clear (IMHO).
No example code is needed for this revision, so I didn't give any, but one or two class definitions might be desirable.
Feedback is quite welcome!
|
msg294521 - (view) |
Author: Raymond Hettinger (rhettinger) * |
Date: 2017-05-26 02:14 |
Overall this looks good. Please do fix the one review comment.
|
msg294532 - (view) |
Author: Raymond Hettinger (rhettinger) * |
Date: 2017-05-26 05:33 |
New changeset 2b44e302ec3079363c4d5c875677945953705c58 by Raymond Hettinger (Aaron Hall, MBA) in branch 'master':
bpo-30449 Terse slots (#1819)
https://github.com/python/cpython/commit/2b44e302ec3079363c4d5c875677945953705c58
|
msg309213 - (view) |
Author: mpb (mpb) |
Date: 2017-12-30 03:15 |
Can __slots__ be assigned a string? If so, what are the consequences? I find the current docs lack clarity. For example from the docs for 3.7.0a3:
https://docs.python.org/3.7/reference/datamodel.html#slots
> 3.3.2.4. __slots__
>
> [snip]
>
> object.__slots__
> This class variable can be assigned a string,
> iterable, or sequence of strings [snip]
However, "3.3.2.4.1. Notes on using __slots__" does not discuss what happens when a string is assigned to __slots__.
The "notes" section does discuss assigning a "sequence of strings" to __slots__.
The "notes" section also says: "Any non-string iterable may be assigned to __slots__."
Based on quick experimentation, it appears that the string must be a single identifier. I get a TypeError if I try to assign "foo bar" to __slots__. The consequence of a string appears to be that only a single slot is created. It would be nice if this was stated clearly in the docs.
The docs for 2.7 seem similar to version 3.7.0a3. So maybe all versions of the docs could be improved regarding the specifics of what happens when you assign a string to __slots__.
|
msg309274 - (view) |
Author: Raymond Hettinger (rhettinger) * |
Date: 2017-12-31 10:56 |
mpb, I think the docs with respect to strings are fine as-is. Sometimes if too much detail is put in, it makes the docs harder to read and understand (i.e. it gets in the way of our primary purpose).
|
msg309293 - (view) |
Author: mpb (mpb) |
Date: 2017-12-31 17:41 |
@rhettinger
I disagree (but you're the boss). If a function can take type X as a parameter, I believe docs should also say what the expected behavior is when you call the function and pass it type X, especially when type X is fundamentally different from every other type the function accepts. (And yes, __slots__ is not a function, but I still find the metaphor apt.)
Cheers!
|
msg311470 - (view) |
Author: Cheryl Sabella (cheryl.sabella) * |
Date: 2018-02-02 00:02 |
It looks like this documentation patch was applied to master. Does it need to be backported to 3.6 and 2.7 for the issue to be closed? Thanks!
|
msg312569 - (view) |
Author: Cheryl Sabella (cheryl.sabella) * |
Date: 2018-02-22 14:42 |
Mariatta,
Do you think this one needs to be backported? You had originally added the labels on the pull request, then removed them. I wasn't sure if that was needed before being able to close this.
Thanks!
|
msg312571 - (view) |
Author: Mariatta (Mariatta) * |
Date: 2018-02-22 17:25 |
Yes I think we can backport this to 3.6 and 2.7.
|
msg312572 - (view) |
Author: Mariatta (Mariatta) * |
Date: 2018-02-22 17:32 |
We can't auto backport to 2.7 because of conflict.
Aaron can you prepare the backport PR?
|
msg312574 - (view) |
Author: Mariatta (Mariatta) * |
Date: 2018-02-22 17:37 |
New changeset 6eab93cfe5ee08a6168e5bb69474e461cc7ac535 by Mariatta (Miss Islington (bot)) in branch '3.6':
bpo-30449: Improve __slots__ documentation (GH-1819)
https://github.com/python/cpython/commit/6eab93cfe5ee08a6168e5bb69474e461cc7ac535
|
|
Date |
User |
Action |
Args |
2022-04-11 14:58:46 | admin | set | github: 74634 |
2019-02-15 23:36:05 | cheryl.sabella | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
2018-02-22 17:37:43 | Mariatta | set | messages:
+ msg312574 |
2018-02-22 17:32:08 | Mariatta | set | messages:
+ msg312572 |
2018-02-22 17:28:00 | miss-islington | set | keywords:
+ patch stage: backport needed -> patch review pull_requests:
+ pull_request5590 |
2018-02-22 17:25:35 | Mariatta | set | stage: patch review -> backport needed |
2018-02-22 17:25:28 | Mariatta | set | messages:
+ msg312571 |
2018-02-22 14:42:22 | cheryl.sabella | set | nosy:
+ Mariatta messages:
+ msg312569
|
2018-02-02 10:00:41 | rhettinger | set | assignee: rhettinger -> |
2018-02-02 00:02:18 | cheryl.sabella | set | nosy:
+ cheryl.sabella messages:
+ msg311470
|
2017-12-31 17:41:41 | mpb | set | messages:
+ msg309293 |
2017-12-31 10:56:12 | rhettinger | set | messages:
+ msg309274 |
2017-12-30 03:15:32 | mpb | set | nosy:
+ mpb messages:
+ msg309213
|
2017-05-26 05:33:28 | rhettinger | set | messages:
+ msg294532 |
2017-05-26 02:14:13 | rhettinger | set | assignee: docs@python -> rhettinger |
2017-05-26 02:14:05 | rhettinger | set | messages:
+ msg294521 |
2017-05-25 21:58:29 | Aaron Hall | set | messages:
+ msg294515 |
2017-05-25 21:43:51 | Aaron Hall | set | pull_requests:
+ pull_request1905 |
2017-05-25 03:50:05 | rhettinger | set | nosy:
+ rhettinger messages:
+ msg294429
|
2017-05-25 01:06:04 | Mariatta | set | versions:
+ Python 3.5 |
2017-05-25 01:04:58 | Mariatta | set | stage: patch review |
2017-05-25 00:30:54 | python-dev | set | pull_requests:
+ pull_request1889 |
2017-05-24 02:25:57 | Aaron Hall | set | messages:
+ msg294310 |
2017-05-24 01:01:47 | Aaron Hall | create | |