Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
The following codes get different results between python3.6.9 and python3.8.10
importargparseif__name__=="__main__":parser=argparse.ArgumentParser(allow_abbrev=False )parser.add_argument('-on',"--output-name",type=str,help="output")args,_=parser.parse_known_args(["-on","name","-o","dir"])print(args)
python3.6.9
[chenf@b12e0231:/mnt/ssd/chenf/projects/test_hhb_2.4/debug/cmd_config]$ python3 --versionPython 3.6.9[chenf@b12e0231:/mnt/ssd/chenf/projects/test_hhb_2.4/debug/cmd_config]$ python3~/test.pyNamespace(output_name='name')
python3.8.10
[chenf@b11b0623:/mnt/ssd/chenf/project/hhb_test_2.4/cmd_config]$ python3 --versionPython 3.8.10[chenf@b11b0623:/mnt/ssd/chenf/project/hhb_test_2.4/cmd_config]$ python3~/test.pyNamespace(output_name='dir')
Debug
I have tried to debug the codes and get some clues.
I have set theallow_abbrev=False to disable prefix match, but it works in python3.6.9 and fails in python3.8.10.
When I div intoargparse.py and find that it considers the allow_abbrev in python3.6.9 but not in python3.8.10 as follow:
in python3.6.9 argparse.py
def_parse_optional(self,arg_string): ....ifself.allow_abbrev:# search through all possible prefixes of the option string# and all actions in the parser for possible interpretationsoption_tuples=self._get_option_tuples(arg_string)# if multiple actions match, the option string was ambiguousiflen(option_tuples)>1:options=', '.join([option_stringforaction,option_string,explicit_arginoption_tuples])args= {'option':arg_string,'matches':options}msg=_('ambiguous option: %(option)s could match %(matches)s')self.error(msg%args)# if exactly one action matched, this segmentation is good,# so return the parsed actioneliflen(option_tuples)==1:option_tuple,=option_tuplesreturnoption_tuple ....
in python3.8.10 argparse.py
def_parse_optional(self,arg_string): ....# search through all possible prefixes of the option string# and all actions in the parser for possible interpretationsoption_tuples=self._get_option_tuples(arg_string)# if multiple actions match, the option string was ambiguousiflen(option_tuples)>1:options=', '.join([option_stringforaction,option_string,explicit_arginoption_tuples])args= {'option':arg_string,'matches':options}msg=_('ambiguous option: %(option)s could match %(matches)s')self.error(msg%args)# if exactly one action matched, this segmentation is good,# so return the parsed actioneliflen(option_tuples)==1:option_tuple,=option_tuplesreturnoption_tuple ....
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Doc issues