Skip to content

Conversation

@emmatyping
Copy link
Member

@emmatyping emmatyping commented Apr 6, 2025

This attribute provides the offset to zip data from the start of the file, when available.

I chose data_offset to avoid confusion with the _offset property that is unrelated.


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

This attribute provides the offset to zip data from the start of the file, when available.
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 6, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@emmatyping
Copy link
Member Author

I have signed the CLA with my current email. (I had already signed it under another email anyway)

@gpshead gpshead merged commit 0788948 into python:main Apr 6, 2025
43 checks passed
self.fp = _Tellable(self.fp)
self.start_dir = 0
self._seekable = False
self._data_offset = None
Copy link
Member

@picnixz picnixz Apr 6, 2025

Choose a reason for hiding this comment

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

It may not be set if mode == 'a' and if BadZipFile is raised. In this case, we should still have a None according to the docs (otherwise an AttributeError will be raised).

For mode 'r', it should be noted that failing _RealGetContents() means that the object will never be initialized so we don't care about the lack of attribute.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe that in this case, since mode 'a' calls tell() unconditionally, we can set the data_offset to the result of that, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Though honestly the defensive thing to do here is to initialize it to None early on then change it later when possible.

Copy link
Member

Choose a reason for hiding this comment

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

Though honestly the defensive thing to do here is to initialize it to None early on then change it later when possible.

Yes, that's what I thought.

seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
* Add ZipFile.data_offset attribute

This attribute provides the offset to zip data from the start of the file, when available.

* Add blurb-it

* Try fixing class ref in NEWS
emmatyping added a commit to emmatyping/cpython that referenced this pull request Jul 21, 2025
gpshead added a commit that referenced this pull request Jul 21, 2025
* Revert "gh-84481: Make ZipFile.data_offset more robust (#132178)"

This reverts commit 6cd1d6c.

* Revert "gh-84481: Add ZipFile.data_offset attribute (#132165)"

This reverts commit 0788948.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 21, 2025
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (pythonGH-132178)"

This reverts commit 6cd1d6c.

* Revert "pythongh-84481: Add ZipFile.data_offset attribute (pythonGH-132165)"

This reverts commit 0788948.

---------
(cherry picked from commit 6bf1c0a)

Co-authored-by: Emma Smith <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
gpshead added a commit that referenced this pull request Jul 22, 2025
…36955)

gh-136170: Revert adding `ZipFile.data_offset` (GH-136950)

* Revert "gh-84481: Make ZipFile.data_offset more robust (GH-132178)"

This reverts commit 6cd1d6c.

* Revert "gh-84481: Add ZipFile.data_offset attribute (GH-132165)"

This reverts commit 0788948.

---------
(cherry picked from commit 6bf1c0a)

Co-authored-by: Emma Smith <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (python#132178)"

This reverts commit 6cd1d6c.

* Revert "pythongh-84481: Add ZipFile.data_offset attribute (python#132165)"

This reverts commit 0788948.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (python#132178)"

This reverts commit 6cd1d6c.

* Revert "pythongh-84481: Add ZipFile.data_offset attribute (python#132165)"

This reverts commit 0788948.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
kumaraditya303 pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2025
…-136950) (python#136955)

pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH-136950)

* Revert "pythongh-84481: Make ZipFile.data_offset more robust (pythonGH-132178)"

This reverts commit 6cd1d6c.

* Revert "pythongh-84481: Add ZipFile.data_offset attribute (pythonGH-132165)"

This reverts commit 0788948.

---------
(cherry picked from commit 6bf1c0a)

Co-authored-by: Emma Smith <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants