Skip to content

gh-122299: fix io.IOBase.seek docs WRT offset type - #121421

Closed
andmis wants to merge 4 commits into
python:mainfrom
andmis:andrey/fix-IOBase-seek-docs
Closed

andmis wants to merge 4 commits into
python:mainfrom
andmis:andrey/fix-IOBase-seek-docs

Conversation

@andmis

@andmis andmis commented Jul 6, 2024 •

Copy link
Copy Markdown
Contributor
>>> s = io.StringIO("😅🙂🤯")
>>> s.seek(1)
1
>>> s.read(1))
'🙂'
>>> s.seek(2)
2
>>> s.read(1)
'🤯'
>>> s.seek(0)
0
>>> len(s.read(1).encode())
4
>>>

📚 Documentation preview 📚: https://cpython-previews--121421.org.readthedocs.build/

@bedevere-app

bedevere-app Bot commented Jul 6, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ghost

ghost commented Jul 6, 2024 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Jul 6, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Jul 6, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Jul 6, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@hauntsaninja hauntsaninja left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, I'm not sure about this. Frankly, I think that documentation in IOBase.seek is just misleading, given that various subclasses differ on their interpretation of the arguments. See also:

s = '😅🙂🤯'

with open("tmp.txt", "w") as f:
    f.write(s)

import io
f = open("tmp.txt")
assert isinstance(f, io.IOBase)
f.seek(1)
f.read()

Currently, StringIO.seek's behaviour is documented under TextIOBase: https://docs.python.org/3/library/io.html#io.TextIOBase.seek (offset must be zero or opaque value obtained from tell). Looks like there's an open issue asking for the better guarantee that you have in this PR: #69377

I'm not sure what the best thing to do here is. I think it would be nice for IOBase to mention that behaviour in subclasses is different. Maybe we should open an issue so docs or io people can weigh in?

@hugovk hugovk changed the title fix io.IOBase.seek docs WRT offset type gh-121421: fix io.IOBase.seek docs WRT offset type Jul 26, 2024
@hugovk hugovk changed the title gh-121421: fix io.IOBase.seek docs WRT offset type gh-122299: fix io.IOBase.seek docs WRT offset type Jul 26, 2024
@andmis andmis closed this Aug 14, 2024
@andmis
andmis deleted the andrey/fix-IOBase-seek-docs branch August 14, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants