Skip to content

Conversation

@AlexWaygood
Copy link
Member

As discussed in #10980. Several of the recipes are deliberately omitted for now; not all are easy to add to our test_cases directory, 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 our test_cases directory relatively easily.

@AlexWaygood
Copy link
Member Author

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.

@AlexWaygood
Copy link
Member Author

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).

@AlexWaygood
Copy link
Member Author

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]:
Copy link
Collaborator

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.

Copy link
Member Author

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 :)

@AlexWaygood AlexWaygood requested a review from srittau November 15, 2023 15:15
@srittau srittau merged commit 968e2be into python:main Nov 15, 2023
@AlexWaygood AlexWaygood deleted the itertools-easy-recipes branch November 15, 2023 15:30
@AlexWaygood
Copy link
Member Author

Our first use of PEP-646 in typeshed! Even if it is only in a test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants