Skip to content
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

Typed seq combine alternative #2

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

robjhornby
Copy link

This PR is part of a response to the Sequences section of this blog post, see there for context. Related issue

Introduce an alternative to parsy's seq parser, with type annotations. This approach combines parser results into a tuple without increasing the nesting level for each extra parser in the sequence. Once a sequence is created, the result tuple can be passed to a function as *args using the previous .combine syntax.

The benefit is that Pyright will check that the result type of each parser in the sequence against the argument types of the combined function. Without needing extra steps like un-nesting tuples from the result.

For example, in the screenshot below, the demo function expects its first argument to have a type of str. A parser of type Parser[int, str, bool] can be made with the join and append functions. Then where combine is called, VSCode shows that there's a problem - the parser result type doesn't match demo's parameter type in the first argument.

image

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.

1 participant