Skip to content

gh-114552: Update __dir__ method docs: it allows returning an iterable#114662

Merged
AlexWaygood merged 3 commits into
python:mainfrom
sobolevn:issue-114552
Feb 10, 2024
Merged

gh-114552: Update __dir__ method docs: it allows returning an iterable#114662
AlexWaygood merged 3 commits into
python:mainfrom
sobolevn:issue-114552

Conversation

@sobolevn

@sobolevn sobolevn commented Jan 27, 2024

Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update line 2012 as well? As I noted in #114552 (comment), it seems also to be incorrect

@sobolevn

sobolevn commented Jan 27, 2024

Copy link
Copy Markdown
Member Author

2012 was a good year :)
Updated.

@AlexWaygood

AlexWaygood commented Jan 27, 2024

Copy link
Copy Markdown
Member

Do we have any tests that assert that non-sequence iterables are okay to be returned from __dir__ methods? If not, could you add some as part of this PR? :)

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd like for us to wait a little bit before merging, in case anybody else has objections (changing the language spec shouldn't be done lightly, in my opinion)

@terryjreedy terryjreedy added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Feb 1, 2024

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the backport labels because I consider this a doc bugfix. The __dir__ doc should have always matched the __dir__ behavior, and indeed they do as long as 'sequence' is properly interpreded. Since the new iterator protocol added the new term 'iterable', an iterable is the obvious requirement. The sloppiness of using 'sequence' when 'iterable' is meant is partly a holdover from the old protocol when only objects with a sequence __getitem__ could be iterated. We are still cleaning up this confusion in the docs.

My perspective is likely colored from having started with 1.3, just before 1.4.

I since read Alex's comment. To me, we are clarifying, not changing, the language spec. I am sure we have made other /sequence/interable/ changes but I cannot remember if they were backported.

@AlexWaygood AlexWaygood merged commit e19103a into python:main Feb 10, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @sobolevn for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 10, 2024
… iterable (pythonGH-114662)

(cherry picked from commit e19103a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app

bedevere-app Bot commented Feb 10, 2024

Copy link
Copy Markdown

GH-115234 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 10, 2024
… iterable (pythonGH-114662)

(cherry picked from commit e19103a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Feb 10, 2024
@bedevere-app

bedevere-app Bot commented Feb 10, 2024

Copy link
Copy Markdown

GH-115235 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Feb 10, 2024
AlexWaygood pushed a commit that referenced this pull request Feb 10, 2024
…n iterable (GH-114662) (#115234)

gh-114552: Update `__dir__` method docs: it allows returning an iterable (GH-114662)
(cherry picked from commit e19103a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
AlexWaygood pushed a commit that referenced this pull request Feb 10, 2024
…n iterable (GH-114662) (#115235)

gh-114552: Update `__dir__` method docs: it allows returning an iterable (GH-114662)
(cherry picked from commit e19103a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants