-
Notifications
You must be signed in to change notification settings - Fork 276
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
Extend tests to include newly-added data types #759
base: main
Are you sure you want to change the base?
Conversation
@danieldk Does this kind of modification to the tests reflect what you had in mind? If so, I'll go on adjusting the others that are relevant w.r.t. #599 (comment). |
Looks good indeed! I don't think this is easily possible, but maybe something we want to look into longer term -- ideally, we'd generate examples based on the type signatures. So, if the type signature would change, the generated data would change with it. Though, I think that's probably a very large undertaking, so going though the types and trying to modify the tests accordingly seems like the best short-term solution. |
That's interesting - is there already a concept on how to do that? I can imagine having a function deriving input types from another function like @pytest.mark.parametrize("cpu_ops", CPU_OPS)
@settings(max_examples=MAX_EXAMPLES * 2, deadline=None)
@given(X=strategies.generate_examples_for(ops.flatten))
def test_flatten_unflatten_roundtrip(cpu_ops: NumpyOps, X: numpy.ndarray):
... where This sketch doesn't feel like that much work though, so I'm probably overlooking something 😄 |
No, I don't think we have anything like that yet.
Try it 👍. As long as it's opt-in per test, we could enable them gradually. For reviewing I think it's the nicest to do this as a proof of concept for maybe two or three methods first. Avoids a lot of rewrites as a result of review comments. Then once we are happy with the design, we could apply it to more methods. |
Looked into this a bit. From Python 3.7 upwards this kind of type resolution would definitely work, 3.6 and below is a bit of a pain. To resolve function return type annotations into proper types, something like this would be necessary in 3.6 ( import inspect
from typing import _eval_type
# Extract all types in Union. This only works if those types are imported already.
types = [_eval_type(arg, globals(), globals()) for arg in inspect.signature(fn).return_annotation.__args__] Whereas in Python 3.7+ it'd be from typing import get_type_hints, get_args # type_extensions in 3.7, typing in 3.8+
types = get_args(get_type_hints(fn)["return"]]) So in 3.6 we'd have to use private method and resolve the Considering this I'd recommend implementing the type-dynamic testing once |
Sounds completely sensible to me, we should avoid relying on internals of external dependencies. |
An alternative to waiting for 3.6 support to be dropped before implementing the tests would be to decorate them with
|
👷 Deploy request for thinc-ai pending review.Visit the deploys page to approve it
|
Description
Extend tests to include data types added via relaxed signatures in #599.
Types of change
Enhancement / chore.
Checklist
In response to #599 (comment).