Fix regression with settings with a '-'

This commit is contained in:
Timmy Welch 2023-01-31 19:35:10 -08:00
parent 983fe782a3
commit 577b43c4e8
No known key found for this signature in database
2 changed files with 40 additions and 2 deletions

View File

@ -201,7 +201,7 @@ if TYPE_CHECKING:
def sanitize_name(name: str) -> str: def sanitize_name(name: str) -> str:
return re.sub('[' + re.escape(' -_,.!@#$%^&*(){}[]\',."<>;:') + ']+', '-', name).strip('-') return re.sub('[' + re.escape(' -_,.!@#$%^&*(){}[]\',."<>;:') + ']+', '_', name).strip('_')
def get_option(options: Values | Namespace, setting: Setting) -> tuple[Any, bool]: def get_option(options: Values | Namespace, setting: Setting) -> tuple[Any, bool]:

View File

@ -64,6 +64,44 @@ example: list[tuple[list[str], str, str]] = [
), ),
] ]
success = [ success = [
(
(
('--test-setting',),
dict(
group='tst',
),
), # Equivalent to Setting("--test-setting", group="tst")
{
'action': None,
'choices': None,
'cmdline': True,
'const': None,
'default': None,
'dest': 'test_setting', # dest is calculated by Setting and is not used by argparse
'exclusive': False,
'file': True,
'group': 'tst',
'help': None,
'internal_name': 'tst_test_setting', # Should almost always be "{group}_{dest}"
'metavar': 'TEST_SETTING', # Set manually so argparse doesn't use TST_TEST
'nargs': None,
'required': None,
'type': None,
'argparse_args': ('--test-setting',), # *args actually sent to argparse
'argparse_kwargs': {
'action': None,
'choices': None,
'const': None,
'default': None,
'dest': 'tst_test_setting',
'help': None,
'metavar': 'TEST_SETTING',
'nargs': None,
'required': None,
'type': None,
}, # Non-None **kwargs sent to argparse
},
),
( (
( (
('--test',), ('--test',),
@ -71,7 +109,7 @@ success = [
group='tst', group='tst',
dest='testing', dest='testing',
), ),
), # Equivalent to Setting("--test", group="tst") ), # Equivalent to Setting("--test", group="tst", dest="testing")
{ {
'action': None, 'action': None,
'choices': None, 'choices': None,