From 12bd79729e248ff0f966023f05342e1445a99542 Mon Sep 17 00:00:00 2001 From: Foo Date: Fri, 6 Jan 2017 21:23:42 +0300 Subject: [PATCH] Improve removing arguments from documentation Examples of issues where user used arguments which should not be present in documentation, but actually were present: #1699 (cpu_load_percent: shutdown_event), #1700 (weather: key, after_update, shutdown_event). --- powerline/lib/threaded.py | 23 ++++++++++++++--------- powerline/lint/inspect.py | 2 ++ powerline/segments/common/env.py | 2 +- powerline/segments/common/players.py | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/powerline/lib/threaded.py b/powerline/lib/threaded.py index 01ad2a0d..e5a6b3e7 100644 --- a/powerline/lib/threaded.py +++ b/powerline/lib/threaded.py @@ -158,17 +158,16 @@ class ThreadedSegment(Segment, MultiRunnedThread): def additional_args(self): return (('interval', self.interval),) + _omitted_args = { + 'render': (0,), + 'set_state': ('shutdown_event',), + } + def omitted_args(self, name, method): + ret = self._omitted_args.get(name, ()) if isinstance(getattr(self, name, None), MethodType): - omitted_indexes = (0,) - else: - omitted_indexes = () - if name.startswith('render'): - if omitted_indexes: - omitted_indexes += (1,) - else: - omitted_indexes = (0,) - return omitted_indexes + ret = tuple((i + 1 if isinstance(i, int) else i for i in ret)) + return ret class KwThreadedSegment(ThreadedSegment): @@ -255,3 +254,9 @@ class KwThreadedSegment(ThreadedSegment): @staticmethod def render_one(update_state, **kwargs): return update_state + + _omitted_args = { + 'render': ('update_value', 'key', 'after_update'), + 'set_state': ('shutdown_event',), + 'render_one': (0,), + } diff --git a/powerline/lint/inspect.py b/powerline/lint/inspect.py index b6e0380b..15bb6103 100644 --- a/powerline/lint/inspect.py +++ b/powerline/lint/inspect.py @@ -39,7 +39,9 @@ def getconfigargspec(obj): for i, arg in enumerate(reversed(argspec.args)): if ( largs - (i + 1) in omitted_args + or arg in omitted_args or arg == 'pl' + or arg == 'self' or (arg == 'create_watcher' and requires_filesystem_watcher) or (arg == 'segment_info' and requires_segment_info) ): diff --git a/powerline/segments/common/env.py b/powerline/segments/common/env.py index ec28be7f..e4a2428b 100644 --- a/powerline/segments/common/env.py +++ b/powerline/segments/common/env.py @@ -44,7 +44,7 @@ class CwdSegment(Segment): def omitted_args(self, name, method): if method is self.get_shortened_path: - return (0, 1, 2) + return () else: return super(CwdSegment, self).omitted_args(name, method) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index 333612cb..32277a67 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -62,7 +62,7 @@ class PlayerSegment(Segment): yield 'get_player_status', self.get_player_status def omitted_args(self, name, method): - return (0,) + return () _common_args = '''