mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Fix error message for invalidly providing type arguments to NamedTuple
when it occurs in a type expression (#19940)
This commit is contained in:
parent
527a690a73
commit
f4d8826428
2 changed files with 6 additions and 2 deletions
|
@ -312,6 +312,9 @@ def expects_named_tuple(x: typing.NamedTuple):
|
||||||
|
|
||||||
def _(y: type[typing.NamedTuple]):
|
def _(y: type[typing.NamedTuple]):
|
||||||
reveal_type(y) # revealed: @Todo(unsupported type[X] special form)
|
reveal_type(y) # revealed: @Todo(unsupported type[X] special form)
|
||||||
|
|
||||||
|
# error: [invalid-type-form] "Special form `typing.NamedTuple` expected no type parameter"
|
||||||
|
def _(z: typing.NamedTuple[int]): ...
|
||||||
```
|
```
|
||||||
|
|
||||||
Any instance of a `NamedTuple` class can therefore be passed for a function parameter that is
|
Any instance of a `NamedTuple` class can therefore be passed for a function parameter that is
|
||||||
|
|
|
@ -10783,7 +10783,8 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
||||||
SpecialFormType::TypingSelf
|
SpecialFormType::TypingSelf
|
||||||
| SpecialFormType::TypeAlias
|
| SpecialFormType::TypeAlias
|
||||||
| SpecialFormType::TypedDict
|
| SpecialFormType::TypedDict
|
||||||
| SpecialFormType::Unknown => {
|
| SpecialFormType::Unknown
|
||||||
|
| SpecialFormType::NamedTuple => {
|
||||||
self.infer_type_expression(arguments_slice);
|
self.infer_type_expression(arguments_slice);
|
||||||
|
|
||||||
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
||||||
|
@ -10808,7 +10809,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
||||||
SpecialFormType::Tuple => {
|
SpecialFormType::Tuple => {
|
||||||
Type::tuple(self.infer_tuple_type_expression(arguments_slice))
|
Type::tuple(self.infer_tuple_type_expression(arguments_slice))
|
||||||
}
|
}
|
||||||
SpecialFormType::Generic | SpecialFormType::Protocol | SpecialFormType::NamedTuple => {
|
SpecialFormType::Generic | SpecialFormType::Protocol => {
|
||||||
self.infer_expression(arguments_slice);
|
self.infer_expression(arguments_slice);
|
||||||
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
|
||||||
builder.into_diagnostic(format_args!(
|
builder.into_diagnostic(format_args!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue