Omit typing module from flake8-type-checking by default (#2277)

This commit is contained in:
Charlie Marsh 2023-01-27 18:19:45 -05:00 committed by GitHub
parent 7320058ce2
commit d1aaf16e40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -3120,7 +3120,7 @@ and can be circumvented via `eval` or `importlib`.
Exempt certain modules from needing to be moved into type-checking Exempt certain modules from needing to be moved into type-checking
blocks. blocks.
**Default value**: `[]` **Default value**: `["typing"]`
**Type**: `Vec<String>` **Type**: `Vec<String>`
@ -3128,7 +3128,7 @@ blocks.
```toml ```toml
[tool.ruff.flake8-type-checking] [tool.ruff.flake8-type-checking]
exempt-modules = ["typing_extensions"] exempt-modules = ["typing", "typing_extensions"]
``` ```
--- ---

View File

@ -25,10 +25,10 @@ pub struct Options {
/// See: https://github.com/snok/flake8-type-checking#strict. /// See: https://github.com/snok/flake8-type-checking#strict.
pub strict: Option<bool>, pub strict: Option<bool>,
#[option( #[option(
default = "[]", default = "[\"typing\"]",
value_type = "Vec<String>", value_type = "Vec<String>",
example = r#" example = r#"
exempt-modules = ["typing_extensions"] exempt-modules = ["typing", "typing_extensions"]
"# "#
)] )]
/// Exempt certain modules from needing to be moved into type-checking /// Exempt certain modules from needing to be moved into type-checking
@ -36,17 +36,28 @@ pub struct Options {
pub exempt_modules: Option<Vec<String>>, pub exempt_modules: Option<Vec<String>>,
} }
#[derive(Debug, Hash, Default)] #[derive(Debug, Hash)]
pub struct Settings { pub struct Settings {
pub strict: bool, pub strict: bool,
pub exempt_modules: Vec<String>, pub exempt_modules: Vec<String>,
} }
impl Default for Settings {
fn default() -> Self {
Self {
strict: false,
exempt_modules: vec!["typing".to_string()],
}
}
}
impl From<Options> for Settings { impl From<Options> for Settings {
fn from(options: Options) -> Self { fn from(options: Options) -> Self {
Self { Self {
strict: options.strict.unwrap_or_default(), strict: options.strict.unwrap_or(false),
exempt_modules: options.exempt_modules.unwrap_or_default(), exempt_modules: options
.exempt_modules
.unwrap_or_else(|| vec!["typing".to_string()]),
} }
} }
} }