From ebca5c2df8a733156bb261ae763bd1561f2195e3 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 30 Dec 2022 13:09:56 +0100 Subject: [PATCH] Make banned-api config setting optional (#1465) --- ruff.schema.json | 8 ++++---- src/flake8_tidy_imports/settings.rs | 6 +++--- src/settings/pyproject.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ruff.schema.json b/ruff.schema.json index 337a83ab88..5fb13c8fae 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1095,9 +1095,6 @@ }, "Flake8TidyImportsOptions": { "type": "object", - "required": [ - "banned-api" - ], "properties": { "ban-relative-imports": { "description": "Whether to ban all relative imports (`\"all\"`), or only those imports that extend into the parent module or beyond (`\"parents\"`).", @@ -1112,7 +1109,10 @@ }, "banned-api": { "description": "Specific modules or module members that may not be imported or accessed. Note that this check is only meant to flag accidental uses, and can be circumvented via `eval` or `importlib`.", - "type": "object", + "type": [ + "object", + "null" + ], "additionalProperties": { "$ref": "#/definitions/BannedApi" } diff --git a/src/flake8_tidy_imports/settings.rs b/src/flake8_tidy_imports/settings.rs index ed6a573e24..51d1b4ea87 100644 --- a/src/flake8_tidy_imports/settings.rs +++ b/src/flake8_tidy_imports/settings.rs @@ -56,7 +56,7 @@ pub struct Options { /// Specific modules or module members that may not be imported or accessed. /// Note that this check is only meant to flag accidental uses, /// and can be circumvented via `eval` or `importlib`. - pub banned_api: FxHashMap, + pub banned_api: Option>, } #[derive(Debug)] @@ -78,7 +78,7 @@ impl From for Settings { fn from(options: Options) -> Self { Self { ban_relative_imports: options.ban_relative_imports.unwrap_or(Strictness::Parents), - banned_api: options.banned_api, + banned_api: options.banned_api.unwrap_or_default(), } } } @@ -87,7 +87,7 @@ impl From for Options { fn from(settings: Settings) -> Self { Self { ban_relative_imports: Some(settings.ban_relative_imports), - banned_api: settings.banned_api, + banned_api: Some(settings.banned_api), } } } diff --git a/src/settings/pyproject.rs b/src/settings/pyproject.rs index a2a90dde8c..bbdb245637 100644 --- a/src/settings/pyproject.rs +++ b/src/settings/pyproject.rs @@ -515,7 +515,7 @@ other-attribute = 1 }), flake8_tidy_imports: Some(flake8_tidy_imports::settings::Options { ban_relative_imports: Some(Strictness::Parents), - banned_api: FxHashMap::from_iter([ + banned_api: Some(FxHashMap::from_iter([ ( "cgi".to_string(), BannedApi { @@ -528,7 +528,7 @@ other-attribute = 1 msg: "Use typing_extensions.TypedDict instead.".to_string() } ) - ]) + ])) }), flake8_import_conventions: Some(flake8_import_conventions::settings::Options { aliases: Some(FxHashMap::from_iter([(