mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +00:00
Rename parser mode from Jupyter
to Ipython
(#7153)
This commit is contained in:
parent
e02d76f070
commit
1adde24133
9 changed files with 35 additions and 41 deletions
|
@ -150,7 +150,7 @@ pub fn parse_program_tokens(
|
|||
is_jupyter_notebook: bool,
|
||||
) -> anyhow::Result<Suite, ParseError> {
|
||||
let mode = if is_jupyter_notebook {
|
||||
Mode::Jupyter
|
||||
Mode::Ipython
|
||||
} else {
|
||||
Mode::Module
|
||||
};
|
||||
|
@ -267,15 +267,8 @@ pub enum Mode {
|
|||
Module,
|
||||
/// The code consists of a single expression.
|
||||
Expression,
|
||||
/// The code consists of a sequence of statements which are part of a
|
||||
/// Jupyter Notebook and thus could include escape commands scoped to
|
||||
/// a single line.
|
||||
///
|
||||
/// ## Limitations:
|
||||
///
|
||||
/// For [Dynamic object information], the escape characters (`?`, `??`)
|
||||
/// must be used before an object. For example, `?foo` will be recognized,
|
||||
/// but `foo?` will not.
|
||||
/// The code consists of a sequence of statements which can include the
|
||||
/// escape commands that are part of IPython syntax.
|
||||
///
|
||||
/// ## Supported escape commands:
|
||||
///
|
||||
|
@ -290,7 +283,7 @@ pub enum Mode {
|
|||
/// [Dynamic object information]: https://ipython.readthedocs.io/en/stable/interactive/reference.html#dynamic-object-information
|
||||
/// [System shell access]: https://ipython.readthedocs.io/en/stable/interactive/reference.html#system-shell-access
|
||||
/// [Automatic parentheses and quotes]: https://ipython.readthedocs.io/en/stable/interactive/reference.html#automatic-parentheses-and-quotes
|
||||
Jupyter,
|
||||
Ipython,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Mode {
|
||||
|
@ -299,7 +292,7 @@ impl std::str::FromStr for Mode {
|
|||
match s {
|
||||
"exec" | "single" => Ok(Mode::Module),
|
||||
"eval" => Ok(Mode::Expression),
|
||||
"jupyter" => Ok(Mode::Jupyter),
|
||||
"ipython" => Ok(Mode::Ipython),
|
||||
_ => Err(ModeParseError),
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +306,7 @@ impl AsMode for PySourceType {
|
|||
fn as_mode(&self) -> Mode {
|
||||
match self {
|
||||
PySourceType::Python | PySourceType::Stub => Mode::Module,
|
||||
PySourceType::Ipynb => Mode::Jupyter,
|
||||
PySourceType::Ipynb => Mode::Ipython,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +317,7 @@ pub struct ModeParseError;
|
|||
|
||||
impl std::fmt::Display for ModeParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, r#"mode must be "exec", "eval", "jupyter", or "single""#)
|
||||
write!(f, r#"mode must be "exec", "eval", "ipython", or "single""#)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue