diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index aae885b88bc5e1..8939e879cba088 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -2147,16 +2147,18 @@ where ]) { if let Some(operator) = typing::to_pep604_operator(value, slice, &self.semantic) { - if self.enabled(Rule::FutureRewritableTypeAnnotation) { - if self.settings.target_version < PythonVersion::Py310 - && self.settings.target_version >= PythonVersion::Py37 - && !self.semantic.future_annotations() - && self.semantic.in_annotation() - && !self.settings.pyupgrade.keep_runtime_typing - { - flake8_future_annotations::rules::future_rewritable_type_annotation( - self, value, - ); + if !self.is_stub { + if self.enabled(Rule::FutureRewritableTypeAnnotation) { + if self.settings.target_version < PythonVersion::Py310 + && self.settings.target_version >= PythonVersion::Py37 + && !self.semantic.future_annotations() + && self.semantic.in_annotation() + && !self.settings.pyupgrade.keep_runtime_typing + { + flake8_future_annotations::rules::future_rewritable_type_annotation( + self, value, + ); + } } } if self.enabled(Rule::NonPEP604Annotation) { @@ -2175,17 +2177,19 @@ where } // Ex) list[...] - if self.enabled(Rule::FutureRequiredTypeAnnotation) { - if self.settings.target_version < PythonVersion::Py39 - && !self.semantic.future_annotations() - && self.semantic.in_annotation() - && typing::is_pep585_generic(value, &self.semantic) - { - flake8_future_annotations::rules::future_required_type_annotation( - self, - expr, - flake8_future_annotations::rules::Reason::PEP585, - ); + if !self.is_stub { + if self.enabled(Rule::FutureRequiredTypeAnnotation) { + if self.settings.target_version < PythonVersion::Py39 + && !self.semantic.future_annotations() + && self.semantic.in_annotation() + && typing::is_pep585_generic(value, &self.semantic) + { + flake8_future_annotations::rules::future_required_type_annotation( + self, + expr, + flake8_future_annotations::rules::Reason::PEP585, + ); + } } } @@ -2273,16 +2277,18 @@ where if let Some(replacement) = typing::to_pep585_generic(expr, &self.semantic) { - if self.enabled(Rule::FutureRewritableTypeAnnotation) { - if self.settings.target_version < PythonVersion::Py39 - && self.settings.target_version >= PythonVersion::Py37 - && !self.semantic.future_annotations() - && self.semantic.in_annotation() - && !self.settings.pyupgrade.keep_runtime_typing - { - flake8_future_annotations::rules::future_rewritable_type_annotation( - self, expr, - ); + if !self.is_stub { + if self.enabled(Rule::FutureRewritableTypeAnnotation) { + if self.settings.target_version < PythonVersion::Py39 + && self.settings.target_version >= PythonVersion::Py37 + && !self.semantic.future_annotations() + && self.semantic.in_annotation() + && !self.settings.pyupgrade.keep_runtime_typing + { + flake8_future_annotations::rules::future_rewritable_type_annotation( + self, expr, + ); + } } } if self.enabled(Rule::NonPEP585Annotation) { @@ -2350,16 +2356,18 @@ where Rule::NonPEP585Annotation, ]) { if let Some(replacement) = typing::to_pep585_generic(expr, &self.semantic) { - if self.enabled(Rule::FutureRewritableTypeAnnotation) { - if self.settings.target_version < PythonVersion::Py39 - && self.settings.target_version >= PythonVersion::Py37 - && !self.semantic.future_annotations() - && self.semantic.in_annotation() - && !self.settings.pyupgrade.keep_runtime_typing - { - flake8_future_annotations::rules::future_rewritable_type_annotation( - self, expr, - ); + if !self.is_stub { + if self.enabled(Rule::FutureRewritableTypeAnnotation) { + if self.settings.target_version < PythonVersion::Py39 + && self.settings.target_version >= PythonVersion::Py37 + && !self.semantic.future_annotations() + && self.semantic.in_annotation() + && !self.settings.pyupgrade.keep_runtime_typing + { + flake8_future_annotations::rules::future_rewritable_type_annotation( + self, expr, + ); + } } } if self.enabled(Rule::NonPEP585Annotation) { @@ -3142,16 +3150,18 @@ where .. }) => { // Ex) `str | None` - if self.enabled(Rule::FutureRequiredTypeAnnotation) { - if self.settings.target_version < PythonVersion::Py310 - && !self.semantic.future_annotations() - && self.semantic.in_annotation() - { - flake8_future_annotations::rules::future_required_type_annotation( - self, - expr, - flake8_future_annotations::rules::Reason::PEP604, - ); + if !self.is_stub { + if self.enabled(Rule::FutureRequiredTypeAnnotation) { + if self.settings.target_version < PythonVersion::Py310 + && !self.semantic.future_annotations() + && self.semantic.in_annotation() + { + flake8_future_annotations::rules::future_required_type_annotation( + self, + expr, + flake8_future_annotations::rules::Reason::PEP604, + ); + } } }