Skip to content

Commit

Permalink
[red-knot] Any cannot be parameterized (#14933)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Dec 12, 2024
1 parent 82faa9b commit 45b565c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ y: int = Subclass() # error: [invalid-assignment]
def _(s: Subclass):
reveal_type(s) # revealed: Subclass
```

## Invalid

`Any` cannot be parameterized:

```py
from typing import Any

# error: [invalid-type-parameter] "Type `typing.Any` expected no type parameter"
def f(x: Any[int]):
reveal_type(x) # revealed: Unknown
```
12 changes: 11 additions & 1 deletion crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4863,7 +4863,17 @@ impl<'db> TypeInferenceBuilder<'db> {
}
KnownInstanceType::Type => self.infer_subclass_of_type_expression(parameters),
KnownInstanceType::Tuple => self.infer_tuple_type_expression(parameters),
KnownInstanceType::Any => Type::Any,
KnownInstanceType::Any => {
self.diagnostics.add_lint(
&INVALID_TYPE_PARAMETER,
subscript.into(),
format_args!(
"Type `{}` expected no type parameter",
known_instance.repr(self.db)
),
);
Type::Unknown
}
}
}

Expand Down

0 comments on commit 45b565c

Please sign in to comment.