Skip to content

Commit

Permalink
Close #18538: python -m dis now uses argparse.
Browse files Browse the repository at this point in the history
Patch by Michele Orrù.
  • Loading branch information
ncoghlan committed Aug 24, 2013
1 parent e726ce1 commit 0956689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
27 changes: 8 additions & 19 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,25 +436,14 @@ def display_code(self, *, file=None):

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__":
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0956689

Please sign in to comment.