-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] Property tests #14178
base: main
Are you sure you want to change the base?
[red-knot] Property tests #14178
Conversation
c1f05ab
to
634b4f6
Compare
let db = setup_db(); | ||
|
||
let t1 = t1.into_type(&db); | ||
let t2 = t2.into_type(&db); | ||
let t3 = t3.into_type(&db); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to move forward with this, we could probably auto-generate this boilerplate in each test using a macro.
## Summary Minor fix to `Type::is_subtype_of` to make sure that Boolean literals are subtypes of `int`, to match runtime semantics. Found this while doing some property-testing experiments [1]. [1] #14178 ## Test Plan New unit test.
|
if size == 0 { | ||
arbitrary_core_type(g) | ||
} else { | ||
match u32::arbitrary(g) % 4 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be a better way to do this. If only we had the author of this library on our team...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC: @BurntSushi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks reasonable to me?
This is awesome! Thank you for doing this, I've been wanting to explore this. I think property testing is very well suited to testing type relation invariants, and I do think we should move forward with actually landing this. |
c1086b8
to
87c67df
Compare
Summary
This is something I played with, wondering if it could be useful. It found a few bugs so far:
Literal[True] <: int
#14177~Any
/~Unknown
#14195is_assignable_to
for unions #14196is_disjoint_from
for class literals #14210If we want to merge this, there are a few things to do / to consider:
The tests are extremely slow at the moment (> 30 ms per iteration in debug mode; > 3 ms in release mode) . The reason for this is our incredible naive way of setting up theThe tests are now three orders of magnitude faster.TestDb
in every iteration. This is hopefully easy to fix by caching theTestDb
.int | str
is equal tostr | int
, there is an open TODO in the code)Never
. For example:tuple[Never, int]
is equivalent toNever
, but we currently don't simplify this anywhere.str & Any & ~tuple[Any] & ~tuple[Unknown] & ~Literal[""] & ~Literal["a"] | str & int & ~tuple[Any] & ~tuple[Unknown]
), requiring the developer to simplify manuallyTest Plan