8000 Fix argument parsing in newer Python. · colcon/colcon-core@b39c91c · GitHub
[go: up one dir, main page]

Skip to content

Commit b39c91c

Browse files
committed
Fix argument parsing in newer Python.
The comment in the code has more details, but as of python/cpython#114180 we need to check for both a 3-tuple and a 4-tuple. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
1 parent 532e213 commit b39c91c
< 8000 /div>

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

colcon_core/command.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,14 @@ class CustomArgumentParser(argparse.ArgumentParser):
226226

227227
def _parse_optional(self, arg_string):
228228
result = super()._parse_optional(arg_string)
229-
if result == (None, arg_string, None):
229+
# Up until https://github.com/python/cpython/pull/114180 ,
230+
# _parse_optional() returned a 3-tuple when it couldn't classify
231+
# the option. As of that PR (which is in Python 3.13, and
232+
# backported to Python 3.12), it returns a 4-tuple. Check for
233+
# either here.
234+
if result in (
235+
(None, arg_string, None), (None, arg_string, None, None)
236+
):
230237
# in the case there the arg is classified as an unknown 'O'
231238
# override that and classify it as an 'A'
232239
return None

0 commit comments

Comments
 (0)
0