From 917bba1f2a382d5251b94eeadc344ec6ed3eaa97 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 22 Aug 2010 08:01:58 +0000 Subject: [PATCH] Issue #9214: Fix set operations on KeysView and ItemsView. --- Lib/_abcoll.py | 8 ++++++++ Misc/NEWS | 3 +++ 2 files changed, 11 insertions(+) diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index a442d7c8a7..e9234af382 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -390,6 +390,10 @@ class MappingView(Sized): class KeysView(MappingView, Set): + @classmethod + def _from_iterable(self, it): + return set(it) + def __contains__(self, key): return key in self._mapping @@ -400,6 +404,10 @@ class KeysView(MappingView, Set): class ItemsView(MappingView, Set): + @classmethod + def _from_iterable(self, it): + return set(it) + def __contains__(self, item): key, value = item try: diff --git a/Misc/NEWS b/Misc/NEWS index e10f33dd3c..d4fb9f2927 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #9214: Set operations on KeysView or ItemsView in the collections + module now correctly return a set. (Patch by Eli Bendersky.) + - Issue #9617: Signals received during a low-level write operation aren't ignored by the buffered IO layer anymore. -- 2.50.1