-
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.
|
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
40de0e3
to
207eb44
Compare
quickcheck = { version = "1.0.3" } | ||
quickcheck_macros = { version = "1.0.0" } |
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.
Dev-dependencies can't be optional, otherwise I would have made these dependent on the property_tests
feature.
207eb44
to
7ccc8c6
Compare
7ccc8c6
to
6c44442
Compare
Summary
This PR adds a new
property_tests
module with quickcheck-based tests that verify certain properties of types. The following properties are currently checked:is_equivalent_to
:T
is equivalent to itselfis_subtype_of
:T
is a subtype ofT
S <: T
andT <: S
, thenS
is equivalent toT
S <: T
&T <: U
=>S <: U
is_disjoint_from
:T
is not disjoint fromT
S
disjoint fromT
=>T
disjoint fromS
is_assignable_to
:negate
:T.negate().negate()
is equivalent toT
There are also some tests that validate higher-level properties like:
S <: T
implies thatS
is not disjoint fromT
S <: T
implies thatS
is assignable toT
These tests found a few bugs so far:
Literal[True] <: int
#14177~Any
/~Unknown
#14195is_assignable_to
for unions #14196is_disjoint_from
for class literals #14210Literal
instances and_SpecialForm
#14731Some additional notes:
int | str
is the same asstr | int
, for example.is_disjoint_from
andis_subtype_of
can produce false negative answers.str & Any & ~tuple[Any] & ~tuple[Unknown] & ~Literal[""] & ~Literal["a"] | str & int & ~tuple[Any] & ~tuple[Unknown]
), requiring the developer to simplify manually. It has not been a major issue so far, but there is a comment in the code how this can be improved.Test Plan