From 975df2b3ebf69069f4299e201b178aaaa4349aed Mon Sep 17 00:00:00 2001 From: mhassan1 Date: Fri, 6 Dec 2024 13:06:50 -0500 Subject: [PATCH] cli: fix `TypeError` in `HelpfulArgumentParser` for python 3.12.8 and 3.13.1 (related #15687) Signed-off-by: mhassan1 --- awxkit/awxkit/cli/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/awxkit/awxkit/cli/utils.py b/awxkit/awxkit/cli/utils.py index 61c2fe8f5e9e..888e3831a264 100644 --- a/awxkit/awxkit/cli/utils.py +++ b/awxkit/awxkit/cli/utils.py @@ -40,13 +40,20 @@ def error(self, message): # pragma: nocover self._print_message('\n') self.exit(2, '%s: %s\n' % (self.prog, message)) - def _parse_known_args(self, args, ns): + def _parse_known_args(self, args, ns, intermixed = False): for arg in ('-h', '--help'): # the -h argument is extraneous; if you leave it off, # awx-cli will just print usage info if arg in args: args.remove(arg) - return super(HelpfulArgumentParser, self)._parse_known_args(args, ns) + + super__parse_known_args = super(HelpfulArgumentParser, self)._parse_known_args + # python <=3.12.7 and ==3.13.0 have an arg count of 3 + # python ~=3.12.8 and >=3.13.1 have an arg count of 4 + # https://github.com/python/cpython/pull/125356/files#diff-205ef24c9374465bf35c359abce9211d3aa113e986a1e3d41569eb29d07df479R1967 + if super__parse_known_args.__code__.co_argcount == 3: + return super__parse_known_args(args, ns) + return super__parse_known_args(args, ns, intermixed) def color_enabled():