From 18a0a8f9f28d94280af512a827d13c981c900036 Mon Sep 17 00:00:00 2001 From: Rohan-Salwan Date: Fri, 26 Nov 2021 13:02:57 +0530 Subject: [PATCH 1/3] enhancement of issue295 --- fire/helptext.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fire/helptext.py b/fire/helptext.py index b1d10b44..e91afbc9 100644 --- a/fire/helptext.py +++ b/fire/helptext.py @@ -35,6 +35,8 @@ import itertools import sys +import inspect +from types import FunctionType from fire import completion from fire import custom_descriptions @@ -68,6 +70,7 @@ def HelpText(component, trace=None, verbose=False): metadata = decorators.GetMetadata(component) # Sections: + spec.args=Checker(spec,component) name_section = _NameSection(component, info, trace=trace, verbose=verbose) synopsis_section = _SynopsisSection( component, actions_grouped_by_kind, spec, metadata, trace=trace) @@ -95,6 +98,42 @@ def HelpText(component, trace=None, verbose=False): ) +def Checker(spec,component): + """ + desc: + Checker funcition firstly checks type of component and afterthat + it extract all parent classes. + Return: + case 1: If there is any parent class it will return all_args list. + case 2: If there is no parent class so it will return only args list. + """ + if type(component) is not FunctionType and type(component) is not object: + try: + Inherit_classes_list=inspect.getmro(component) + if len(Inherit_classes_list)>2: + return ReturnAllArgs(Inherit_classes_list) + except AttributeError as e: + pass + + return spec.args + + +def ReturnAllArgs(Inherit_classes_list): + """ + Inherit_classes_list: It is a list which have collection of parent classes. + Return: list of all arguments which is retrieved from parent classes. + """ + all_args = [] + if len(Inherit_classes_list)>2: + for classes in Inherit_classes_list: + argspec_tuple=inspect.getargspec(classes) + args_list=argspec_tuple[0] + for arg in args_list[1:]: + all_args.append(arg) + + return all_args + + def _NameSection(component, info, trace=None, verbose=False): """The "Name" section of the help string.""" From 99f026766a56d92826d0d225fc284c519b85d6af Mon Sep 17 00:00:00 2001 From: Rohan-Salwan Date: Sun, 5 Dec 2021 16:24:26 +0530 Subject: [PATCH 2/3] fix repetitive condition --- fire/helptext.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fire/helptext.py b/fire/helptext.py index e91afbc9..0ac30c57 100644 --- a/fire/helptext.py +++ b/fire/helptext.py @@ -67,10 +67,10 @@ def HelpText(component, trace=None, verbose=False): info = inspectutils.Info(component) actions_grouped_by_kind = _GetActionsGroupedByKind(component, verbose=verbose) spec = inspectutils.GetFullArgSpec(component) + spec.args = Checker(spec,component) metadata = decorators.GetMetadata(component) # Sections: - spec.args=Checker(spec,component) name_section = _NameSection(component, info, trace=trace, verbose=verbose) synopsis_section = _SynopsisSection( component, actions_grouped_by_kind, spec, metadata, trace=trace) @@ -124,12 +124,12 @@ def ReturnAllArgs(Inherit_classes_list): Return: list of all arguments which is retrieved from parent classes. """ all_args = [] - if len(Inherit_classes_list)>2: - for classes in Inherit_classes_list: - argspec_tuple=inspect.getargspec(classes) - args_list=argspec_tuple[0] - for arg in args_list[1:]: - all_args.append(arg) + + for classes in Inherit_classes_list: + argspec_tuple=inspect.getargspec(classes) + args_list=argspec_tuple[0] + for arg in args_list[1:]: + all_args.append(arg) return all_args From 92258a30b4c056037cfe8dd55a7b2bd2533f71fb Mon Sep 17 00:00:00 2001 From: Rohan-Salwan Date: Thu, 13 Jan 2022 02:46:14 +0530 Subject: [PATCH 3/3] fix typos --- fire/helptext.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fire/helptext.py b/fire/helptext.py index 0ac30c57..c9311426 100644 --- a/fire/helptext.py +++ b/fire/helptext.py @@ -104,34 +104,34 @@ def Checker(spec,component): Checker funcition firstly checks type of component and afterthat it extract all parent classes. Return: - case 1: If there is any parent class it will return all_args list. + case 1: If there is any parent class it will return all parameters in list. case 2: If there is no parent class so it will return only args list. """ if type(component) is not FunctionType and type(component) is not object: try: Inherit_classes_list=inspect.getmro(component) if len(Inherit_classes_list)>2: - return ReturnAllArgs(Inherit_classes_list) + return ReturnParentParameters(Inherit_classes_list) except AttributeError as e: pass return spec.args -def ReturnAllArgs(Inherit_classes_list): +def ReturnParentParameters(Inherit_classes_list): """ Inherit_classes_list: It is a list which have collection of parent classes. - Return: list of all arguments which is retrieved from parent classes. + Return: list of all parameters which is retrieved from parent classes. """ - all_args = [] + all_parameters = [] for classes in Inherit_classes_list: argspec_tuple=inspect.getargspec(classes) - args_list=argspec_tuple[0] - for arg in args_list[1:]: - all_args.append(arg) + args_spec=argspec_tuple[0] + for parameter in args_spec[1:]: + all_parameters.append(parameter) - return all_args + return all_parameters def _NameSection(component, info, trace=None, verbose=False):