-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add several itertools recipes to the test_cases directory
#10992
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
Conversation
|
The recipes themselves are copied-and-pasted from the itertools docs, docstrings and comments included. All I've done to them is add type annotations where necessary, in order to get our tests to pass. |
|
In total, this adds 24/33 recipes (25 if you count the one I "added" that's commented out, because it really needs PEP-646). |
Now it is 25/33, since the one that needs PEP-646 has been uncommented :) |
| return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)) | ||
|
|
||
|
|
||
| def polynomial_derivative(coefficients: Sequence[int]) -> list[int]: |
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.
Also works with float and other types that can be multiplied with ints (decimal?). It could be worthwhile to use a type var here, but that's optional.
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've gone with float for now. In theory we could do some complex union with Decimal and other numeric types, or a protocol, or a typevar bound to a union/protocol. But I think it would probably just add complexity without actually adding much to the quality of the test (these annotations won't be exposed to our users, after all). Let me know if you disagree :)
|
Our first use of PEP-646 in typeshed! Even if it is only in a test case |
As discussed in #10980. Several of the recipes are deliberately omitted for now; not all are easy to add to our
test_casesdirectory, for various reasons. I defer the ones where certain decisions might need debate to future PRs; this PR attempts to add only the recipes which can be added to ourtest_casesdirectory relatively easily.