Skip to content

Commit

Permalink
Duplicated alias for commands are skipped
Browse files Browse the repository at this point in the history
In 3.11 a bug with duplicated names/aliases of subparsers was fixed in
python/cpython#83897. This leads to an argument
error being raised whenever a duplicate is found. In previous python
versions additional parsers were just overridden without a warning.
  • Loading branch information
kkalinowski-reef committed Nov 11, 2022
1 parent 2f2817e commit ef0fb99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 13 additions & 7 deletions b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,19 @@ def get_parser(cls, subparsers=None, parents=None, for_docs=False):
)
else:
name, alias = cls.name_and_alias()
parser = subparsers.add_parser(
name,
description=description,
parents=parents,
aliases=[alias] if alias is not None and not for_docs else (),
for_docs=for_docs,
)
try:
parser = subparsers.add_parser(
name,
description=description,
parents=parents,
aliases=[alias] if alias is not None and not for_docs else (),
for_docs=for_docs,
)
except argparse.ArgumentError:
# In 3.11 a bug with duplicated subparsers was fixed https://github.com/python/cpython/issues/83897
# This leads to argument error, since all our parsers are registered for both name and alias.
# Whenever a name appears again an ArgumentError is raised, and we simply skip it.
return

cls._setup_parser(parser)

Expand Down
9 changes: 7 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#
######################################################################

import io
import os
import pkg_resources
import platform
Expand All @@ -24,7 +23,13 @@
NO_STATICX = os.environ.get('NO_STATICX') is not None
NOX_PYTHONS = os.environ.get('NOX_PYTHONS')

PYTHON_VERSIONS = ['3.7', '3.8', '3.9', '3.10'] if NOX_PYTHONS is None else NOX_PYTHONS.split(',')
PYTHON_VERSIONS = [
'3.7',
'3.8',
'3.9',
'3.10',
'3.11',
] if NOX_PYTHONS is None else NOX_PYTHONS.split(',')
PYTHON_DEFAULT_VERSION = PYTHON_VERSIONS[-1]

PY_PATHS = ['b2', 'test', 'noxfile.py', 'setup.py']
Expand Down

0 comments on commit ef0fb99

Please sign in to comment.