Skip to content

Commit c10f0f5

Browse files
migeed-zmeta-codesync[bot]
authored andcommitted
Add testcase showing that we do not reveal hover enough info for models
Summary: I will followup with some basic support for this by encoding some of the most common types. In case I face any challanges encoding some of the types (I haven't seen any material challanges yet), I am strongly considering that for a field type annotation 'T' fallback be `T || Any` rather than just `Any`. That way, the hover info is still useful and if we face any tricky situations where we can't encode every single type in the conversion table, the hover information would still be useful. Reviewed By: rchen152 Differential Revision: D87829610 fbshipit-source-id: a6f9689f4db97f06e30efdaf28da3c51c049bc0d
1 parent 2202837 commit c10f0f5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pyrefly/lib/test/pydantic/strict.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,24 @@ Model2(x=0)
102102
Model2(x='0') # E: `Literal['0']` is not assignable to parameter `x`
103103
"#,
104104
);
105+
106+
pydantic_testcase!(
107+
bug = "Revealed type should be more informative",
108+
test_lax_mode_coercion,
109+
r#"
110+
from pydantic import BaseModel
111+
from typing import reveal_type
112+
113+
class Model(BaseModel):
114+
x: int = 0
115+
116+
reveal_type(Model.__init__) # E: revealed type: (self: Model, *, x: Any = ..., **Unknown) -> None
117+
118+
# int field accepts: int, bool, float, str, bytes
119+
Model(x=1)
120+
Model(x=True)
121+
Model(x=1.0)
122+
Model(x='123')
123+
Model(x=b'123')
124+
"#,
125+
);

0 commit comments

Comments
 (0)