Skip to content

Commit d750ee5

Browse files
srinivasreddymerwok
andcommitted
Update Lib/pydoc.py
Co-authored-by: Éric <[email protected]>
1 parent c21f342 commit d750ee5

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Lib/pydoc.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,26 +384,29 @@ def ispackage(path):
384384
return True
385385
return False
386386

387-
def source_synopsis(file_):
388-
"""Takes a file object and returns the one-line summary if present"""
389-
if hasattr(file_, 'buffer'):
390-
file_ = file_.buffer
391-
if isinstance(file_, io.TextIOBase):
387+
def source_synopsis(file):
388+
"""Return the one-line summary of a file object, if present"""
389+
if hasattr(file, 'buffer'):
390+
file = file.buffer
391+
if isinstance(file, io.TextIOBase):
392392
try:
393-
file_ = io.BytesIO(bytes(file_.read(), 'utf-8'))
393+
file = io.BytesIO(bytes(file.read(), 'utf-8'))
394394
except UnicodeEncodeError:
395-
# exception is raised if both utf-8 and latin-1 don't work
396-
file_ = io.BytesIO(bytes(file_.read(), 'latin-1'))
395+
# an exception will be raised if both utf-8 and latin-1 don't work
396+
file = io.BytesIO(bytes(file.read(), 'latin-1'))
397397

398-
tokens = tokenize.tokenize(file_.readline)
398+
tokens = tokenize.tokenize(file.readline)
399399

400-
# tokenize always returns atleast ENCODING and ENDMARKER
401-
for _token in tokens:
402-
_token.name = token.tok_name[_token.type]
403-
if _token.name not in ['COMMENT', 'NL', 'ENCODING']:
400+
# tokenize always returns at least ENCODING and ENDMARKER
401+
for token in tokens:
402+
token_name = token.tok_name[token.type]
403+
if token.name not in {'COMMENT', 'NL', 'ENCODING'}:
404404
break
405-
if _token.name == 'STRING':
406-
return ast.literal_eval(_token.string).strip().split('\n')[0].strip()
405+
406+
# xxx may not be set
407+
if token_name == 'STRING':
408+
return ast.literal_eval(token.string).strip().split('\n')[0].strip()
409+
407410
return None
408411

409412
def synopsis(filename, cache={}):

0 commit comments

Comments
 (0)