Skip to content

Commit

Permalink
Fix argument parsing in newer Python. (#635)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
clalancette committed Apr 9, 2024
1 parent eb53f12 commit b04d936
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion colcon_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ class CustomArgumentParser(argparse.ArgumentParser):

def _parse_optional(self, arg_string):
result = super()._parse_optional(arg_string)
if result == (None, arg_string, None):
# Up until https://github.com/python/cpython/pull/114180 ,
# _parse_optional() returned a 3-tuple when it couldn't classify
# the option. As of that PR (which is in Python 3.13, and
# backported to Python 3.12), it returns a 4-tuple. Check for
# either here.
if result in (
(None, arg_string, None),
(None, arg_string, None, None),
):
# in the case there the arg is classified as an unknown 'O'
# override that and classify it as an 'A'
return None
Expand Down
2 changes: 2 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apache
argparse
asyncio
autouse
backported
basepath
bazqux
blocklist
Expand All @@ -17,6 +18,7 @@ configparser
contextlib
coroutine
coroutines
cpython
datetime
debian
debinfo
Expand Down

0 comments on commit b04d936

Please sign in to comment.