[Python-Dev] [Python-checkins] cpython: Userlist.copy() wasn't returning a UserList.

Jim Jewett jimjjewett at gmail.com
Fri May 6 15:49:19 CEST 2011


Do you also want to assert that u is not v, or would that sort of
"copy" be acceptable by some subclasses?

On 5/5/11, raymond.hettinger <python-checkins at python.org> wrote:
> http://hg.python.org/cpython/rev/f20373fcdde5
> changeset:   69865:f20373fcdde5
> user:        Raymond Hettinger <python at rcn.com>
> date:        Thu May 05 14:34:35 2011 -0700
> summary:
>   Userlist.copy() wasn't returning a UserList.
>
> files:
>   Lib/collections/__init__.py |  2 +-
>   Lib/test/test_userlist.py   |  6 ++++++
>   2 files changed, 7 insertions(+), 1 deletions(-)
>
>
> diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
> --- a/Lib/collections/__init__.py
> +++ b/Lib/collections/__init__.py
> @@ -887,7 +887,7 @@
>      def pop(self, i=-1): return self.data.pop(i)
>      def remove(self, item): self.data.remove(item)
>      def clear(self): self.data.clear()
> -    def copy(self): return self.data.copy()
> +    def copy(self): return self.__class__(self)
>      def count(self, item): return self.data.count(item)
>      def index(self, item, *args): return self.data.index(item, *args)
>      def reverse(self): self.data.reverse()
> diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py
> --- a/Lib/test/test_userlist.py
> +++ b/Lib/test/test_userlist.py
> @@ -52,6 +52,12 @@
>                  return str(key) + '!!!'
>          self.assertEqual(next(iter(T((1,2)))), "0!!!")
>
> +    def test_userlist_copy(self):
> +        u = self.type2test([6, 8, 1, 9, 1])
> +        v = u.copy()
> +        self.assertEqual(u, v)
> +        self.assertEqual(type(u), type(v))
> +
>  def test_main():
>      support.run_unittest(UserListTest)
>
>
> --
> Repository URL: http://hg.python.org/cpython
>


More information about the Python-Dev mailing list