summaryrefslogtreecommitdiffstats
path: root/Lib/dis.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-08-24 14:48:17 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-08-24 14:48:17 (GMT)
commit095668914c38c03760aaf6f2cbe04c0bb1aead51 (patch)
treecac960847c3ba28451db6f7c109d9f32ccc92db8 /Lib/dis.py
parente726ce1f3ed6192591d50a88b933e8806ff99a0e (diff)
downloadcpython-095668914c38c03760aaf6f2cbe04c0bb1aead51.zip
cpython-095668914c38c03760aaf6f2cbe04c0bb1aead51.tar.gz
cpython-095668914c38c03760aaf6f2cbe04c0bb1aead51.tar.bz2
Close #18538: ``python -m dis`` now uses argparse.
Patch by Michele OrrĂ¹.
Diffstat (limited to 'Lib/dis.py')
-rw-r--r--Lib/dis.py27
1 files changed, 8 insertions, 19 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 0d62c08..2631f46 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 = "<stdin>"
- 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__":