Skip to content

Commit 52b0a74

Browse files
committed
Fix missing param spec argument generics, fixes #465
1 parent 7abff87 commit 52b0a74

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

crates/zuban_python/src/file/type_computation/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,15 +2159,16 @@ impl<'db: 'x + 'file, 'file, 'i_s, 'c, 'x> TypeComputation<'db, 'file, 'i_s, 'c>
21592159
break;
21602160
}
21612161
TypeVarLike::ParamSpec(param_spec) => {
2162-
given += 1;
21632162
if expected == 1 && slice_type.iter().count() != 1 {
2163+
given += 1;
21642164
// PEP 612 allows us to write C[int, str] instead of C[[int, str]],
21652165
// because "for aesthetic purposes we allow these to be omitted".
21662166
let params =
21672167
self.calculate_simplified_param_spec_generics(&mut slice_type.iter());
21682168
is_single_param_spec = true;
21692169
GenericItem::ParamSpecArg(ParamSpecArg::new(params, None))
21702170
} else if let Some(spec) = type_args.next_param_spec(self, expected == 1) {
2171+
given += 1;
21712172
GenericItem::ParamSpecArg(spec)
21722173
} else if let Some(default) = param_spec.default(db) {
21732174
resolve_default(

crates/zuban_python/tests/mypylike/tests/type-definitions.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,3 +1232,11 @@ func2(Cls.IN_CLASS) # E: Argument 1 to "func2" has incompatible type "Sentinel(
12321232
func3(1) # ok
12331233
func3(MISSING) # E: Argument 1 to "func3" has incompatible type "Sentinel('<MISSING>')"; expected "int | Sentinel('Cls.IN_CLASS')"
12341234
func3(Cls.IN_CLASS) # ok
1235+
1236+
[case no_crash_on_type_with_missing_param_spec_argument]
1237+
# From GH #465
1238+
class Base[T, **P]:
1239+
def m(self, *args: P.args, **kwargs: P.kwargs) -> T: ...
1240+
1241+
x: Base[int] # E: "Base" expects 2 type arguments, but 1 given
1242+
x.m # Should not cause problems

0 commit comments

Comments
 (0)