mirror of
https://github.com/beetbox/beets.git
synced 2025-12-18 22:57:34 +01:00
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.
This commit is contained in:
parent
f346853710
commit
70ef96d565
1 changed files with 5 additions and 0 deletions
|
|
@ -210,6 +210,11 @@ class ConfigView(object):
|
|||
def __repr__(self):
|
||||
return '<ConfigView: %s>' % 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue