Skip to content

Commit

Permalink
Skip flake8-future-annotations checks in stub files
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 10, 2023
1 parent 82317ba commit e793c21
Showing 1 changed file with 61 additions and 51 deletions.
112 changes: 61 additions & 51 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
);
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
);
}
}
}

Expand Down

0 comments on commit e793c21

Please sign in to comment.