-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SourceKind
a required parameter
#7013
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
let error_location = | ||
if let Some(jupyter_index) = self.source_kind.as_ipy_notebook().map(Notebook::index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change in this section of the diff otherwise it's just a formatter change.
/// Return the [`Notebook`] if the source kind is [`SourceKind::IpyNotebook`]. | ||
pub fn notebook(&self) -> Option<&Notebook> { | ||
if let Self::IpyNotebook(notebook) = self { | ||
Some(notebook) | ||
} else { | ||
None | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required because of is_macro::Is
usage on the enum.
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
error!("Failed to extract source from {}", path.display()); | ||
return None; | ||
}; | ||
match add_noqa_to_path(path, package, &source_kind, source_type, settings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe unify the error handling either by using LintSource::try_from_path(...).and_then(|source| add_noqa_to_path(...))
or extracing into its own function and calling it.
7017574
to
b369b12
Compare
b25806a
to
e7a7910
Compare
…7035) ## Summary This PR refactors the error-handling cases around Jupyter notebooks to use errors rather than `Box<Diagnostics>`, which creates some oddities in the downstream handling. So, instead of formatting errors as diagnostics _eagerly_ (in the notebook methods), we now return errors and convert those errors to diagnostics at the last possible moment (in `diagnostics.rs`). This is more ergonomic, as errors can be composed and reported-on in different ways, whereas diagnostics require a `Printer`, etc. See, e.g., #7013 (comment). ## Test Plan Ran `cargo run` over a Python file labeled with a `.ipynb` suffix, and saw: ``` foo.ipynb:1:1: E999 SyntaxError: Expected a Jupyter Notebook, which must be internally stored as JSON, but found a Python source file: expected value at line 1 column 1 ```
b369b12
to
856f9c2
Compare
856f9c2
to
9c84798
Compare
(Closing and re-opening the PR to trigger CI) |
Summary
This PR refactors the
check_path
function to makeSourceKind
a required parameter i.e., remove theOption<...>
. The main blocker for this change was thatadd_noqa
wasn't supported for Jupyter Notebooks but it's still fine to pass in theSourceKind
without it. This is ok because thePySourceType
is checked before and we don't proceed unless it's either a Python or stub file.This is also required for the PEP 701 f-string parser changes because we want the source code to be available while parsing to extract the leading and trailing text for debug expressions. Here,
SourceKind
will provide that but it was anOption<...>
before.