Skip to content

Commit 5e6a78b

Browse files
committed
Remove the redundant binary file check
1 parent 08cf0a5 commit 5e6a78b

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

Lib/pydoc.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,27 +389,18 @@ def source_synopsis(file):
389389

390390
if hasattr(file, 'buffer'):
391391
file = file.buffer
392-
if isinstance(file, io.TextIOBase):
393-
try:
394-
source = file.read()
395-
except UnicodeDecodeError:
396-
return None
397-
else:
398-
# Binary file
399-
try:
400-
source = tokenize.untokenize(tokenize.tokenize(file.readline))
401-
except (tokenize.TokenError, UnicodeDecodeError):
402-
return None
403392

404393
try:
394+
source = file.read()
405395
tree = ast.parse(source)
396+
406397
if (tree.body and isinstance(tree.body[0], ast.Expr) and
407398
isinstance(tree.body[0].value, ast.Constant) and
408399
isinstance(tree.body[0].value.value, str)):
409400
docstring = tree.body[0].value.value
410401
return docstring.strip().split('\n')[0].strip()
411402
return None
412-
except (SyntaxError, ValueError) as e:
403+
except (UnicodeDecodeError, SyntaxError, ValueError) as e:
413404
return None
414405

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

0 commit comments

Comments
 (0)