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
4 changes: 3 additions & 1 deletion pyrefly/lib/alt/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2694,9 +2694,11 @@ impl<'ctx, 'answer, Ans: LookupAnswer> AnswersSolver<'ctx, 'answer, Ans> {
Type::Annotated(_, _) => acc.push(AttributeBase1::ClassInstance(
self.stdlib.generic_alias().clone(),
)),
Type::TypeForm(_) => {
acc.push(AttributeBase1::ClassInstance(self.stdlib.object().clone()))
}
// TODO: check to see which ones should have class representations
Type::SpecialForm(_)
| Type::TypeForm(_)
| Type::TypeLevelDslCall(_)
| Type::Unpack(_)
| Type::Concatenate(_, _)
Expand Down
26 changes: 26 additions & 0 deletions pyrefly/lib/test/typeform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,29 @@ X: TypeForm[int] = int
x: X = 0 # E: Expected a type form, got instance of `TypeForm[int]`
"#,
);

testcase!(
test_typeform_attribute_access,
r#"
import typing
from typing import TypeVar
from typing_extensions import TypeForm

T = TypeVar("T")

def field_names(tp: TypeForm[T]):
if typing.is_typeddict(tp):
return tp.__annotations__.keys()
return ()
"#,
);

testcase!(
test_typeform_attribute_access_unknown,
r#"
from typing_extensions import TypeForm

def f(tp: TypeForm[int]):
tp.not_a_real_attribute # E: Object of class `object` has no attribute `not_a_real_attribute`
"#,
);
Loading