Do not override Powerline.setup(), use .do_setup() for this

Same reason as for `.__init__()` which was replaced by `.init()`
This commit is contained in:
ZyX 2014-08-18 22:45:32 +04:00
parent 696f4d2357
commit ff78eaa35c
4 changed files with 15 additions and 8 deletions

View File

@ -744,11 +744,21 @@ class Powerline(object):
def setup(self, *args, **kwargs):
'''Setup the environment to use powerline.
To be overridden by subclasses, this one only saves args and kwargs and
unsets shutdown_event.
Must not be overridden by subclasses. This one only saves setup
arguments for :py:meth:`reload` method and calls :py:meth:`do_setup`.
'''
self.shutdown_event.clear()
self.setup_args = (args, kwargs)
self.do_setup(*args, **kwargs)
@staticmethod
def do_setup():
'''Function that does initialization
Should be overridden by subclasses. May accept any number of regular or
keyword arguments.
'''
pass
def reload(self):
'''Reload powerline after update.

View File

@ -56,6 +56,5 @@ class IpythonPowerline(Powerline):
mergedicts(r, self.theme_overrides[name])
return r
def setup(self, attr, obj):
def do_setup(self, attr, obj):
setattr(obj, attr, self)
super(IpythonPowerline, self).setup(attr, obj)

View File

@ -43,9 +43,8 @@ class ShellPowerline(Powerline):
for key, val in local_themes.items()
))
def setup(self, obj):
def do_setup(self, obj):
obj.powerline = self
super(ShellPowerline, self).setup(obj)
def get_argparser(parser=None, *args, **kwargs):

View File

@ -110,8 +110,7 @@ class VimPowerline(Powerline):
except KeyError:
return super(VimPowerline, self).get_config_paths()
def setup(self, pyeval=None, pycmd=None, can_replace_pyeval=True):
super(VimPowerline, self).setup()
def do_setup(self, pyeval=None, pycmd=None, can_replace_pyeval=True):
import __main__
if not pyeval:
pyeval = 'pyeval' if sys.version_info < (3,) else 'py3eval'