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.

Author aeros
Recipients aeros, benjamin.peterson, stutzbach
Date 2019-07-20.04:00:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563595223.34.0.142119222061.issue37635@roundup.psfhosted.org>
In-reply-to
Content
In Python 3.1, three constants were added to the IO module to be used for the whence argument of seek():

    SEEK_SET or 0 – start of the stream
    SEEK_CUR or 1 – current stream position
    SEEK_END or 2 – end of the stream

However, there are at least 102 occurrences across CPython where the integer values are used instead. This only includes instances when a value for the whence arg is explicitly specified. All of the occurrences can be easily found with the usage of git grep:

git grep -E "seek\(-?[0-9]+, [0-2]\)"

This doesn't affect functionality in any way, but it would result in significant readability improvement if these were all replaced with constants. The only requirement would be importing IO or manually specifying the value of constants. 

For simplicity, I would probably start with anything that directly involves IO. The largest number of occurrences are in Lib/test/test_io, so that probably would be the best place to begin. Also, this module already imports io anyways, so it would be a straightforward find and replace. 

It would also be quite useful to make this change in the documentation, in Doc/tutorial/inputoutput there are 4 occurrences. If anything, anyone less familiar with the IO module in general would be the most likely to benefit from this change so modifying the tutorial would likely be the most useful change for the majority of users.

As a single example of what I'm talking about, here's line 334 of Lib/test/test_io:

self.assertEqual(f.seek(-1, 1), 5)

I would propose changing it to:

self.assertEqual(f.seek(-1, io.SEEK_CUR), 5)
History
Date User Action Args
2019-07-20 04:00:23aerossetrecipients: + aeros, benjamin.peterson, stutzbach
2019-07-20 04:00:23aerossetmessageid: <1563595223.34.0.142119222061.issue37635@roundup.psfhosted.org>
2019-07-20 04:00:23aeroslinkissue37635 messages
2019-07-20 04:00:22aeroscreate