From: Nick Coghlan Date: Sat, 24 Aug 2013 14:48:17 +0000 (+1000) Subject: Close #18538: ``python -m dis`` now uses argparse. X-Git-Tag: v3.4.0a2~130 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=095668914c38c03760aaf6f2cbe04c0bb1aead51;p=python Close #18538: ``python -m dis`` now uses argparse. Patch by Michele Orrù. --- diff --git a/Lib/dis.py b/Lib/dis.py index 0d62c0828c..2631f46091 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -436,25 +436,14 @@ class Bytecode: def _test(): """Simple test program to disassemble a file.""" - if sys.argv[1:]: - if sys.argv[2:]: - sys.stderr.write("usage: python dis.py [-|file]\n") - sys.exit(2) - fn = sys.argv[1] - if not fn or fn == "-": - fn = None - else: - fn = None - if fn is None: - f = sys.stdin - else: - f = open(fn) - source = f.read() - if fn is not None: - f.close() - else: - fn = "" - code = compile(source, fn, "exec") + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('infile', type=argparse.FileType(), nargs='?', default='-') + args = parser.parse_args() + with args.infile as infile: + source = infile.read() + code = compile(source, args.infile.name, "exec") dis(code) if __name__ == "__main__": diff --git a/Misc/NEWS b/Misc/NEWS index 53255250e6..55aca64917 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,9 @@ Core and Builtins Library ------- +- Issue #18538: ``python -m dis`` now uses argparse for argument processing. + Patch by Michele Orrù. + - Issue #18394: Close cgi.FieldStorage's optional file. - Issue #17702: On error, os.environb now removes suppress the except context