-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
pyflakes.extend-generics
setting (#4677)
- Loading branch information
1 parent
c8166f2
commit e2ac0cd
Showing
14 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import TYPE_CHECKING | ||
from django.db.models import ForeignKey | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
class Foo: | ||
var = ForeignKey["Path"]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Settings for the `Pyflakes` plugin. | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use ruff_macros::{CacheKey, CombineOptions, ConfigurationOptions}; | ||
|
||
#[derive( | ||
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions, | ||
)] | ||
#[serde( | ||
deny_unknown_fields, | ||
rename_all = "kebab-case", | ||
rename = "PyflakesOptions" | ||
)] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
pub struct Options { | ||
#[option( | ||
default = r#"[]"#, | ||
value_type = "list[str]", | ||
example = "extend-generics = [\"django.db.models.ForeignKey\"]" | ||
)] | ||
/// Additional functions or classes to consider generic, such that any | ||
/// subscripts should be treated as type annotation (e.g., `ForeignKey` in | ||
/// `django.db.models.ForeignKey["User"]`. | ||
pub extend_generics: Option<Vec<String>>, | ||
} | ||
|
||
#[derive(Debug, Default, CacheKey)] | ||
pub struct Settings { | ||
pub extend_generics: Vec<String>, | ||
} | ||
|
||
impl From<Options> for Settings { | ||
fn from(options: Options) -> Self { | ||
Self { | ||
extend_generics: options.extend_generics.unwrap_or_default(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Settings> for Options { | ||
fn from(settings: Settings) -> Self { | ||
Self { | ||
extend_generics: Some(settings.extend_generics), | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_15.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: crates/ruff/src/rules/pyflakes/mod.rs | ||
--- | ||
F401_15.py:5:25: F401 [*] `pathlib.Path` imported but unused | ||
| | ||
5 | if TYPE_CHECKING: | ||
6 | from pathlib import Path | ||
| ^^^^ F401 | ||
| | ||
= help: Remove unused import: `pathlib.Path` | ||
|
||
ℹ Suggested fix | ||
2 2 | from django.db.models import ForeignKey | ||
3 3 | | ||
4 4 | if TYPE_CHECKING: | ||
5 |- from pathlib import Path | ||
5 |+ pass | ||
6 6 | | ||
7 7 | | ||
8 8 | class Foo: | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
...ff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extend_immutable_calls.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
source: crates/ruff/src/rules/pyflakes/mod.rs | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.