Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pyrefly/lib/alt/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4206,6 +4206,33 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
errors: &ErrorCollector,
) -> Type {
let result = self.expr_check(e, None, errors);
match special_export {
Some(SpecialExport::TypeVar) => {
self.error(
errors,
e.range(),
ErrorKind::InvalidTypeVar,
"TypeVar must be assigned to a variable".to_owned(),
);
}
Some(SpecialExport::ParamSpec) => {
self.error(
errors,
e.range(),
ErrorKind::InvalidParamSpec,
"ParamSpec must be assigned to a variable".to_owned(),
);
}
Some(SpecialExport::TypeVarTuple) => {
self.error(
errors,
e.range(),
ErrorKind::InvalidTypeVarTuple,
"TypeVarTuple must be assigned to a variable".to_owned(),
);
}
_ => {}
}
if special_export != Some(SpecialExport::AssertType)
&& let Type::ClassType(cls) = &result
&& self.is_coroutine(&result)
Expand Down
10 changes: 10 additions & 0 deletions pyrefly/lib/test/generic_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ Ts = TypeVarTuple(name = "Ts")
"#,
);

testcase!(
test_tvar_bare_call,
r#"
from typing import TypeVar, ParamSpec, TypeVarTuple
TypeVar("T") # E: TypeVar must be assigned to a variable
ParamSpec("P") # E: ParamSpec must be assigned to a variable
TypeVarTuple("Ts") # E: TypeVarTuple must be assigned to a variable
"#,
);

testcase!(
test_tvar_unexpected_keyword,
r#"
Expand Down
2 changes: 1 addition & 1 deletion pyrefly/lib/test/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ testcase!(
test_crash_on_decorator_assign,
r#"
from typing import TypeVar
@T=TypeVar() # E: Expected newline, found `=` # E: Missing argument `name`
@T=TypeVar() # E: Expected newline, found `=` # E: TypeVar must be assigned to a variable # E: Missing argument `name`
"#,
);

Expand Down
Loading