Skip to content

Deprecate UserList.__add__ when the argument is not a sequence #148376

@GasinAn

Description

@GasinAn

Bug report

Bug description:

from collections import UserList

my_userlist = UserList([1, 2, 3])
my_dict = {'a': 10, 'b': 20}

print(my_userlist + my_dict)
print(my_dict + my_userlist)
my_userlist += my_dict
print(my_userlist)

my_userlist = UserList([1, 2, 3])
my_set = {5, 4}

print(my_userlist + my_set)
print(my_set + my_userlist)
my_userlist += my_set
print(my_userlist)

In Lib/collections/__init__.py, it will do self.__class__(self.data + list(other)), self.__class__(list(other) + self.data) and self.data += list(other). However, it allows other to by any iterable object, even if other is a dict object or a set object. Should this be fixed?

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions