Quantcast

[PATCH] config: make config.items() return a copy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] config: make config.items() return a copy

Martin von Zweigbergk via Mercurial-devel
# HG changeset patch
# User Martin von Zweigbergk <[hidden email]>
# Date 1495139917 25200
#      Thu May 18 13:38:37 2017 -0700
# Node ID d4f7ddd317c69bf100ed43d312ceace9f28316f1
# Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
config: make config.items() return a copy

config.items() was iterating over a copy of the data for the the
specified section on Python 2 by using .items(). However, on Python 3,
items() does not make a copy, so let's switch to explicitly making a
copy to make it safe on both Python 2 and Python 3.

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -68,7 +68,7 @@
     def sections(self):
         return sorted(self._data.keys())
     def items(self, section):
-        return self._data.get(section, {}).items()
+        return list(self._data.get(section, {}).iteritems())
     def set(self, section, item, value, source=""):
         if pycompat.ispy3:
             assert not isinstance(value, str), (
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] config: make config.items() return a copy

Jun Wu
Looks good to me.

Excerpts from Martin von Zweigbergk's message of 2017-05-18 13:51:17 -0700:

> # HG changeset patch
> # User Martin von Zweigbergk <[hidden email]>
> # Date 1495139917 25200
> #      Thu May 18 13:38:37 2017 -0700
> # Node ID d4f7ddd317c69bf100ed43d312ceace9f28316f1
> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
> config: make config.items() return a copy
>
> config.items() was iterating over a copy of the data for the the
> specified section on Python 2 by using .items(). However, on Python 3,
> items() does not make a copy, so let's switch to explicitly making a
> copy to make it safe on both Python 2 and Python 3.
>
> diff --git a/mercurial/config.py b/mercurial/config.py
> --- a/mercurial/config.py
> +++ b/mercurial/config.py
> @@ -68,7 +68,7 @@
>      def sections(self):
>          return sorted(self._data.keys())
>      def items(self, section):
> -        return self._data.get(section, {}).items()
> +        return list(self._data.get(section, {}).iteritems())
>      def set(self, section, item, value, source=""):
>          if pycompat.ispy3:
>              assert not isinstance(value, str), (
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] config: make config.items() return a copy

Yuya Nishihara
In reply to this post by Martin von Zweigbergk via Mercurial-devel
On Thu, 18 May 2017 13:51:17 -0700, Martin von Zweigbergk via Mercurial-devel wrote:

> # HG changeset patch
> # User Martin von Zweigbergk <[hidden email]>
> # Date 1495139917 25200
> #      Thu May 18 13:38:37 2017 -0700
> # Node ID d4f7ddd317c69bf100ed43d312ceace9f28316f1
> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
> config: make config.items() return a copy
>
> config.items() was iterating over a copy of the data for the the
> specified section on Python 2 by using .items(). However, on Python 3,
> items() does not make a copy, so let's switch to explicitly making a
> copy to make it safe on both Python 2 and Python 3.

Sounds good. Queued, thanks.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Loading...