This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: seek(count, whence) accepts bogus whence on windows, python2.7
Type: behavior Stage: resolved
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, eryksun, mattip, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2015-02-08 21:38 by mattip, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg235568 - (view) Author: mattip (mattip) * Date: 2015-02-08 21:38
f=open('abc.txt', 'w+')
f.seek(0, 42)

does not raise an exception on windows, python2.7
msg235572 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-02-08 22:38
The whence argument is used in a switch statement that handles SEEK_END and SEEK_CUR. It doesn't raise an error for an invalid whence value. It just falls through to the fsetpos call.

_portable_fseek
https://hg.python.org/cpython/file/648dcafa7e5f/Objects/fileobject.c#l692

    0:000> k 3
    Child-SP          RetAddr           Call Site
    00000000`0021fa68 00000000`1e0ac84f MSVCR90!fsetpos
    00000000`0021fa70 00000000`1e0aeea3 python27!_portable_fseek+0x6f
    00000000`0021faa0 00000000`1e0c3d09 python27!file_seek+0x123

Why does it manually handle whence and call fgetpos/fsetpos instead of calling _fseeki64?

fseek, _fseeki64
https://msdn.microsoft.com/en-us/library/75yw9bf3%28v=vs.90%29.aspx
msg235981 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-02-14 18:19
I can't say why 2.7 doesn't use _fseeki64, but 3.5 certainly does. 

Possibly it's a significant change of behaviour that would break backwards compatibility? Making a currently working call raise new exceptions is certainly worth double-checking before introducing into a maintenance release.
msg366735 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-04-18 18:58
Python 2 is EOL.
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67602
2020-04-18 20:39:05ned.deilysetstatus: open -> closed
resolution: wont fix
stage: resolved
2020-04-18 18:58:11ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg366735
2015-02-14 18:19:33steve.dowersetmessages: + msg235981
2015-02-08 22:38:09eryksunsetnosy: + eryksun
messages: + msg235572
2015-02-08 21:38:58mattipcreate