MCPcopy Create free account
hub / github.com/astral-sh/ruff / new

Method new

crates/ruff_python_formatter/src/string/docstring.rs:881–896  ·  view source on GitHub ↗

Looks for a valid doctest PS1 prompt in the line given. If one was found, then state for a new doctest code example is returned, along with the code example line.

(original: InputDocstringLine<'src>)

Source from the content-addressed store, hash-verified

879 /// If one was found, then state for a new doctest code example is
880 /// returned, along with the code example line.
881 fn new(original: InputDocstringLine<'src>) -> Option<CodeExampleDoctest<'src>> {
882 let trim_start = original.line.trim_start();
883 // Prompts must be followed by an ASCII space character[1].
884 //
885 // [1]: https://github.com/python/cpython/blob/0ff6368519ed7542ad8b443de01108690102420a/Lib/doctest.py#L809-L812
886 let code = trim_start.strip_prefix(">>> ")?;
887 let indent_len = original
888 .line
889 .len()
890 .checked_sub(trim_start.len())
891 .expect("suffix is <= original");
892 let lines = vec![CodeExampleLine { original, code }];
893 let ps1_indent = &original.line[..indent_len];
894 let doctest = CodeExampleDoctest { lines, ps1_indent };
895 Some(doctest)
896 }
897
898 /// Looks for a valid doctest PS2 prompt in the line given. If one is
899 /// found, it is added to this code example and ownership of the example is

Callers

nothing calls this directly

Calls 12

indent_with_suffixFunction · 0.85
trim_startMethod · 0.80
strip_prefixMethod · 0.80
expectMethod · 0.80
ends_withMethod · 0.80
checked_subMethod · 0.45
lenMethod · 0.45
starts_withMethod · 0.45
nameMethod · 0.45
countMethod · 0.45
charsMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected