MCPcopy Index your code
hub / github.com/RustPython/RustPython / source_synopsis

Function source_synopsis

Lib/pydoc.py:389–412  ·  view source on GitHub ↗

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

(file)

Source from the content-addressed store, hash-verified

387 return False
388
389def source_synopsis(file):
390 """Return the one-line summary of a file object, if present"""
391
392 string = ''
393 try:
394 tokens = tokenize.generate_tokens(file.readline)
395 for tok_type, tok_string, _, _, _ in tokens:
396 if tok_type == tokenize.STRING:
397 string += tok_string
398 elif tok_type == tokenize.NEWLINE:
399 with warnings.catch_warnings():
400 # Ignore the "invalid escape sequence" warning.
401 warnings.simplefilter("ignore", SyntaxWarning)
402 docstring = ast.literal_eval(string)
403 if not isinstance(docstring, str):
404 return None
405 return docstring.strip().split('\n')[0].strip()
406 elif tok_type == tokenize.OP and tok_string in ('(', ')'):
407 string += tok_string
408 elif tok_type not in (tokenize.COMMENT, tokenize.NL, tokenize.ENCODING):
409 return None
410 except (tokenize.TokenError, UnicodeDecodeError, SyntaxError):
411 return None
412 return None
413
414def synopsis(filename, cache={}):
415 """Get the one-line summary out of a module file."""

Callers 2

synopsisFunction · 0.85
runMethod · 0.85

Calls 3

isinstanceFunction · 0.85
stripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected