Skip to content

Commit 45b565c

Browse files
authored
[red-knot] Any cannot be parameterized (#14933)
1 parent 82faa9b commit 45b565c

File tree

2 files changed

+23
-1
lines changed
  • crates/red_knot_python_semantic

2 files changed

+23
-1
lines changed

crates/red_knot_python_semantic/resources/mdtest/annotations/any.md

+12
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ y: int = Subclass() # error: [invalid-assignment]
6969
def _(s: Subclass):
7070
reveal_type(s) # revealed: Subclass
7171
```
72+
73+
## Invalid
74+
75+
`Any` cannot be parameterized:
76+
77+
```py
78+
from typing import Any
79+
80+
# error: [invalid-type-parameter] "Type `typing.Any` expected no type parameter"
81+
def f(x: Any[int]):
82+
reveal_type(x) # revealed: Unknown
83+
```

crates/red_knot_python_semantic/src/types/infer.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -4863,7 +4863,17 @@ impl<'db> TypeInferenceBuilder<'db> {
48634863
}
48644864
KnownInstanceType::Type => self.infer_subclass_of_type_expression(parameters),
48654865
KnownInstanceType::Tuple => self.infer_tuple_type_expression(parameters),
4866-
KnownInstanceType::Any => Type::Any,
4866+
KnownInstanceType::Any => {
4867+
self.diagnostics.add_lint(
4868+
&INVALID_TYPE_PARAMETER,
4869+
subscript.into(),
4870+
format_args!(
4871+
"Type `{}` expected no type parameter",
4872+
known_instance.repr(self.db)
4873+
),
4874+
);
4875+
Type::Unknown
4876+
}
48674877
}
48684878
}
48694879

0 commit comments

Comments
 (0)