ruff/crates/ruff_python_parser/src
Dhruv Manilawala 32fa05765a
Use Jupyter mode while parsing Notebook files (#5552)
## Summary

Enable using the new `Mode::Jupyter` for the tokenizer/parser to parse
Jupyter line magic tokens.

The individual call to the lexer i.e., `lex_starts_at` done by various
rules should consider the context of the source code (is this content
from a Jupyter Notebook?). Thus, a new field `source_type` (of type
`PySourceType`) is added to `Checker` which is being passed around as an
argument to the relevant functions. This is then used to determine the
`Mode` for the lexer.

## Test Plan

Add new test cases to make sure that the magic statement is considered
while generating the diagnostic and autofix:
* For `I001`, if there's a magic statement in between two import blocks,
they should be sorted independently

fixes: #6090
2023-08-05 00:32:07 +00:00
..
lexer Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
snapshots Add a TypeParams node to the AST (#6261) 2023-08-02 14:12:45 +00:00
context.rs Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
function.rs Introduce an Arguments AST node for function calls and class definitions (#6259) 2023-08-02 10:01:13 -04:00
lexer.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
lib.rs Use Jupyter mode while parsing Notebook files (#5552) 2023-08-05 00:32:07 +00:00
parser.rs Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
python.lalrpop Box type params and arguments fields on the class definition node (#6275) 2023-08-02 16:47:06 +00:00
python.rs Box type params and arguments fields on the class definition node (#6275) 2023-08-02 16:47:06 +00:00
soft_keywords.rs Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
string.rs Remove Parse trait (#6235) 2023-08-01 18:35:03 +02:00
token.rs Remove unused parser modes 2023-08-01 13:10:07 +02:00
typing.rs Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00