I'm using argparse
to handle the command-line arguments to my program but it seems like the parser accepts arguments I haven't defined. I've managed to reproduce the issue with this minimal example:
import argparse
def init():
parse_args()
exit()
def parse_args():
parser = argparse.ArgumentParser(add_help = False)
parser.add_argument("--kmers")
parser.parse_args()
if __name__ == '__main__':
init()
Save this a in file say a.py
and run:
python a.py --kmers /file.json
This exits normally; surprisingly, the following also works without the parser complaining:
python a.py --kmer /file.json
Which shouldn't be the case as --kmer
is not a defined argument. Running this however raises an error:
python a.py --kmersss /file.json
`kmers.py: error: unrecognized arguments: --kmerss`
It seems to me that the parser accepts an argument as long as it is a unique prefix of something already defined. Is this the case?