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
2 changes: 1 addition & 1 deletion pyrefly/lib/alt/class/pydantic_lax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {

fn expand_type_for_lax_mode(&self, ty: &Type) -> Type {
match ty {
Type::None => ty.clone(),
Type::None | Type::Literal(_) | Type::LiteralString(_) => ty.clone(),
Type::Type(box inner) => Type::Type(Box::new(self.expand_type_for_lax_mode(inner))),
// Tuple types: convert to Iterable[T] where T is a union of expanded element types
Type::Tuple(tuple) => self
Expand Down
15 changes: 15 additions & 0 deletions pyrefly/lib/test/pydantic/dataclasses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ class A:
A(x='0')
"#,
);

pydantic_testcase!(
test_dataclass_literal_strictness,
r#"
from typing import Literal
from pydantic.dataclasses import dataclass
@dataclass
class Example:
value: Literal["MyLiteral"]
Example(value="MyLiteral")
Example(value=2) # E: Argument `Literal[2]` is not assignable to parameter `value` with type `Literal['MyLiteral']` in function `Example.__init__`
"#,
);
3 changes: 1 addition & 2 deletions pyrefly/lib/test/pydantic/strictness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ reveal_type(Model10.__init__) # E: revealed type: (self: Model10, *, u: LaxUUID
);

pydantic_testcase!(
bug = "An error should be raised here",
test_lax_mode_coercion_literals,
r#"
from typing import Literal
Expand All @@ -184,7 +183,7 @@ from pydantic import BaseModel
class Model1(BaseModel):
status: Literal[1]
m = Model1(status="1")
m = Model1(status="1") # E: Argument `Literal['1']` is not assignable to parameter `status` with type `Literal[1]` in function `Model1.__init__`
"#,
);

Expand Down
Loading