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

Method from_str

crates/ruff_python_ast/src/python_version.rs:160–177  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

158 type Err = PythonVersionDeserializationError;
159
160 fn from_str(s: &str) -> Result<Self, Self::Err> {
161 let (major, minor) = s
162 .split_once('.')
163 .ok_or_else(|| PythonVersionDeserializationError::WrongPeriodNumber(Box::from(s)))?;
164
165 Self::try_from((major, minor)).map_err(|err| {
166 // Give a better error message for something like `3.8.5` or `3..8`
167 if matches!(
168 err,
169 PythonVersionDeserializationError::InvalidMinorVersion(_, _)
170 ) && minor.contains('.')
171 {
172 PythonVersionDeserializationError::WrongPeriodNumber(Box::from(s))
173 } else {
174 err
175 }
176 })
177 }
178}
179
180#[cfg(feature = "serde")]

Callers

nothing calls this directly

Calls 2

map_errMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected