Repository navigation
Closed
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2019-05-26.17:36:51.318>
created_at = <Date 2016-07-28.06:15:07.780>
labels = ['3.7', '3.8', 'type-bug', 'library', 'easy']
title = "UserList.__getitem__ doesn't account for slices"
updated_at = <Date 2019-05-26.17:36:51.317>
user = 'https://github.com/staticshock'bugs.python.org fields:
activity = <Date 2019-05-26.17:36:51.317>
actor = 'SilentGhost'
assignee = 'none'
closed = True
closed_date = <Date 2019-05-26.17:36:51.318>
closer = 'SilentGhost'
components = ['Library (Lib)']
creation = <Date 2016-07-28.06:15:07.780>
creator = 'staticshock'
dependencies = []
files = ['43914']
hgrepos = ['351']
issue_num = 27639
keywords = ['patch', 'easy']
message_count = 20.0
messages = ['271503', '271532', '271615', '341618', '341644', '341645', '341647', '341684', '341725', '341726', '341747', '341833', '341854', '341919', '341980', '342131', '342596', '343451', '343551', '343570']
nosy_count = 7.0
nosy_names = ['rhettinger', 'r.david.murray', 'Mark.Shannon', 'serhiy.storchaka', 'vaultah', 'staticshock', 'mblahay']
pr_nums = ['13150', '4981', '13169', '13181', '13203']
priority = 'low'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27639'
versions = ['Python 3.7', 'Python 3.8']Metadata
Metadata
Assignees
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
staticshock commentedon Jul 28, 2016
The docs for UserList say:
However, UserList([])[:] returns a list, not a UserList.
bitdancer commentedon Jul 28, 2016
LGTM, but this is change we should probably only make in a feature release, with a note in the What's New porting section.
rhettinger commentedon Jul 29, 2016
Take a look at the following code from UserList.py in Python2.7 to get an idea of how this was implemented previously:
mblahay commentedon May 6, 2019
Here is a test that more explicitly shows the problem.
It can clearly be seen here that the return type of the slicing operator is list when it should, in this case, be UserList (or whatever class one is using that is derived from UserList).
mblahay commentedon May 6, 2019
The root cause of this issue seems to be the failure to implement type usage in __getitem__ when the deprecated __getslice__ was removed. This is why slicing worked correctly in 2.7, but not the 3.x versions.
In 3.8, the __getitem__ method is used to create the slice, but here we can see that all it does is pass the task to data, which is of type list and then fails to convert the result to the correct type.
Using other methods as examples, the fix should look like this:
mblahay commentedon May 6, 2019
It is also worth noting that the definition of UserList moved from Lib/UserList.py in 2.7 to Lib/collections/init.py in 3.x
mblahay commentedon May 6, 2019
Results from a quick unit test on the proposed changes were positive:
If you compare this result with the one a couple comments above, you can see that the result is no longer a list, but rather of type UserList.
serhiy-storchaka commentedon May 7, 2019
PR 4981 LGTM (except that it would be worth to add the author's name in the NEWS entry). It is sad that it was not reviewed for 2 years and is closed now.
mblahay commentedon May 7, 2019
Thank you for bringing up that PR. My team will review and try to find out why it was closed without a merge.
mblahay commentedon May 7, 2019
Please note that I am working with Erick Cervantes at PyCon2019 on this issue.
mblahay commentedon May 7, 2019
Let it be known that the author of PR 4981 is known as vaultah. He/she personally closed the pull request this morning stating a lack of need to be recognized for the work. Per his/her instructions I am reviewing the changes and incorporating in our solution as needed. Thank you vaultah!
markshannon commentedon May 7, 2019
New changeset b1c3167 by Mark Shannon (Michael Blahay) in branch 'master':
bpo-27639: Correct return type for UserList slicing operation (bpo-13169)
b1c3167
serhiy-storchaka commentedon May 8, 2019
The real name of vaultah is Dmitry Kazakov. His PR LGTM. Did you notice that I recreated the original PR?
mblahay commentedon May 8, 2019
PR 13150, the recreation of PR 4981, was noticed just after I created PR 13169. It was decided to continue forward with PR 13169 since PR 13150 contained changes that were out of scope for BPO-27639 for which it was suspected might have been the cause of the non-merging of PR 4981. Thank for identifying Dmitry; I did my best to give credit where credit was due.
mblahay commentedon May 9, 2019
For those that are wondering what is going on with PR 13181 and PR 13203, those are both for back porting the change to 3.7. The auto generated PR 13181 failed for an unknown reason and then the bot deleted the branch so the PR could not be taken any further. PR 13203 is a manual attempt at the backport which is moving along much for successfully.
mblahay commentedon May 10, 2019
PR 13203 has finally made it through all checks successfully and is now awaiting merging. Please someone pick it up and merge it. Thank you
mblahay commentedon May 15, 2019
PR 13203 is still waiting for merge
mblahay commentedon May 25, 2019
PR 13203 is still waiting for merge
markshannon commentedon May 26, 2019
New changeset f3d9094 by Mark Shannon (Michael Blahay) in branch '3.7':
BPO-27639: Correct return type for UserList slicing operation (bpo-13203)
f3d9094
mblahay commentedon May 26, 2019
Thank you Mark. Everything for this one is complete. The issue may be closed.