Update E402 to work at cell level for notebooks (#8872)

## Summary

This PR updates the `E402` rule to work at cell level for Jupyter
notebooks. This is enabled only in preview to gather feedback.

The implementation basically resets the import boundary flag on the
semantic model when we encounter the first statement in a cell.

Another potential solution is to introduce `E403` rule that is
specifically for notebooks that works at cell level while `E402` will be
disabled for notebooks.

## Test Plan

Add a notebook with imports in multiple cells and verify that the rule
works as expected.

resolves: #8669
This commit is contained in:
Dhruv Manilawala
2023-11-28 18:32:35 -06:00
committed by GitHub
parent 4957d94beb
commit b28556d739
7 changed files with 204 additions and 9 deletions

View File

@@ -68,7 +68,7 @@ pub enum TomlSourceType {
Unrecognized,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, is_macro::Is)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, is_macro::Is)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PySourceType {
/// The source is a Python file (`.py`).