-
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
Add pyflakes.extend-generics
setting
#4677
Merged
charliermarsh
merged 3 commits into
astral-sh:main
from
JonathanPlasse:add-pyflakes-extend-annotated-subscripts
Jun 1, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm little late for the party, but isn't this PR supposed to eliminate this error?
I'm trying to test it, with following config:
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 works if you put
ruff.toml
in the same folder asF401_15.py
.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.
Oh, great, thank you!