diff options
author | Georg Brandl <georg@python.org> | 2013-10-13 20:51:47 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-10-13 20:51:47 +0200 |
commit | 6e22055ee1d2fa4c93abfafc0ab4029b4a808eb7 (patch) | |
tree | d63762099e0496dab07549e90fbc8f5f8c258bb8 /Lib/pdb.py | |
parent | 7ff4520584d18f44f230a92c20a8091297bc08a8 (diff) | |
download | cpython-git-6e22055ee1d2fa4c93abfafc0ab4029b4a808eb7.tar.gz |
pdb: modernize find_function() and add tests for it.
Closes #18714.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-x | Lib/pdb.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py index 1ec83daf43..143b9252e5 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -95,18 +95,11 @@ def find_function(funcname, filename): except OSError: return None # consumer of this info expects the first line to be 1 - lineno = 1 - answer = None - while True: - line = fp.readline() - if line == '': - break - if cre.match(line): - answer = funcname, filename, lineno - break - lineno += 1 - fp.close() - return answer + with fp: + for lineno, line in enumerate(fp, start=1): + if cre.match(line): + return funcname, filename, lineno + return None def getsourcelines(obj): lines, lineno = inspect.findsource(obj) |