Sep-04-2020, 09:10 PM
The below script runs just fine from the command line, but pycharm complains that the formatter_class value in the call to argparse.ArgumentParser is of an "Unexpected type", it says it is expecting "_FormaterClass" as the type.
The class MyFormatter is taken from a response to an earlier post of mine that suggested it and it seems to work without a problem. URL for that discussion is:
Discussion of argparse formatters
Should I be concerned about this pycharm warning?
OS version is Win10 (64-bit) w/latest update, pycharm is version 2020.2.1, python version is 3.8.3 (64-bit).
Peter
The class MyFormatter is taken from a response to an earlier post of mine that suggested it and it seems to work without a problem. URL for that discussion is:
Discussion of argparse formatters
Should I be concerned about this pycharm warning?
OS version is Win10 (64-bit) w/latest update, pycharm is version 2020.2.1, python version is 3.8.3 (64-bit).
Peter
argtest1.py code is:import argparse
MYVERSION = "0.0.1"
# Used by getarguments() to both display default values and leave
# epilog indented as-typed
class MyFormatter(
argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter):
pass
def getarguments():
"""Process and display command-line options using argparse"""
_pgmdesc = "MySript that does something"
_epidesc = ("""\
MyScipt Epilog line 1
MyScipt Epilog line 2
""")
sstparser = argparse.ArgumentParser(description=_pgmdesc,
epilog=_epidesc,
formatter_class=MyFormatter,
fromfile_prefix_chars="@")
sstparser.add_argument("-V", "--version", action="version", version="%(prog)s " + MYVERSION)
sstparser.add_argument("-s", "--randseed", help="Override initial random seed value", type=int, default=0)
sstargs = sstparser.parse_args()
return sstargs
myparse = getarguments()
exit()Output from argtest1.py -h is:Output:usage: argtest1.py [-h] [-V] [-s RANDSEED]
MyScript that does something
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-s RANDSEED, --randseed RANDSEED
Override initial random seed value (default: 0)
MyScipt Epilog line 1
MyScipt Epilog line 2Output from argtest1.py -V is:Output:argtest1.py 0.0.1
