From 70ef96d5655ef003a2657f10525be46dd72258a2 Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Mon, 19 Jan 2015 10:35:32 +0100 Subject: [PATCH] Make list(ui.config) raise a TypeError As per PEP234 (https://www.python.org/dev/peps/pep-0234/) if an object has __getitem__() but not __iter__() then the former will be used to build an iterable, invoking it with 0, then 1, ... until a KeyError is raised. Lazy configuration makes it never happen, and list(config) runs indefinitely, hogging all memory. Implement __iter__(), which raises a TypeError, to solve that problem. --- beets/util/confit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/beets/util/confit.py b/beets/util/confit.py index b157c35a2..ea7d0690b 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -210,6 +210,11 @@ class ConfigView(object): def __repr__(self): return '' % self.name + def __iter__(self): + """Prevent list(config) from using __getitem__ and never halting""" + raise TypeError(u"{!r} object is not " + u"iterable".format(self.__class__.__name__)) + def __getitem__(self, key): """Get a subview of this view.""" return Subview(self, key)