Skip to content

Commit 6daf11e

Browse files
committed
[ty] Disallow Final in function parameter annotations
1 parent 38d8846 commit 6daf11e

File tree

2 files changed

+8
-2
lines changed
  • crates/ty_python_semantic

2 files changed

+8
-2
lines changed

crates/ty_python_semantic/resources/mdtest/type_qualifiers/final.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class C:
275275
self.LEGAL_I: Final[int]
276276
self.LEGAL_I = 1
277277

278-
# TODO: This should be an error
278+
# error: [invalid-type-form] "`Final` is not allowed in function parameter annotations"
279279
def f(ILLEGAL: Final[int]) -> None:
280280
pass
281281
```

crates/ty_python_semantic/src/types/infer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,10 +2431,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
24312431
default: _,
24322432
} = parameter_with_default;
24332433

2434-
self.infer_optional_annotation_expression(
2434+
let annotated = self.infer_optional_annotation_expression(
24352435
parameter.annotation.as_deref(),
24362436
DeferredExpressionState::None,
24372437
);
2438+
2439+
if annotated.is_some_and(|annotated| annotated.qualifiers.contains(TypeQualifiers::FINAL)) {
2440+
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, parameter) {
2441+
builder.into_diagnostic("`Final` is not allowed in function parameter annotations");
2442+
}
2443+
}
24382444
}
24392445

24402446
fn infer_parameter(&mut self, parameter: &ast::Parameter) {

0 commit comments

Comments
 (0)