MCPcopy Index your code
hub / github.com/python/cpython / source_synopsis

Function source_synopsis

Lib/pydoc.py:324–347  ·  view source on GitHub ↗

Return the one-line summary of a file object, if present

(file)

Source from the content-addressed store, hash-verified

322 return False
323
324def source_synopsis(file):
325 """Return the one-line summary of a file object, if present"""
326
327 string = ''
328 try:
329 tokens = tokenize.generate_tokens(file.readline)
330 for tok_type, tok_string, _, _, _ in tokens:
331 if tok_type == tokenize.STRING:
332 string += tok_string
333 elif tok_type == tokenize.NEWLINE:
334 with warnings.catch_warnings():
335 # Ignore the "invalid escape sequence" warning.
336 warnings.simplefilter("ignore", SyntaxWarning)
337 docstring = ast.literal_eval(string)
338 if not isinstance(docstring, str):
339 return None
340 return docstring.strip().split('\n')[0].strip()
341 elif tok_type == tokenize.OP and tok_string in ('(', ')'):
342 string += tok_string
343 elif tok_type not in (tokenize.COMMENT, tokenize.NL, tokenize.ENCODING):
344 return None
345 except (tokenize.TokenError, UnicodeDecodeError, SyntaxError):
346 return None
347 return None
348
349def synopsis(filename, cache={}):
350 """Get the one-line summary out of a module file."""

Callers 2

synopsisFunction · 0.85
runMethod · 0.85

Calls 2

stripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…