-
Notifications
You must be signed in to change notification settings - Fork 133
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
Change Parallelizable
and Collect
to structural subtypes
#1115
Change Parallelizable
and Collect
to structural subtypes
#1115
Conversation
Hey! Thanks for this -- makes sense at a high-level. Also the issue is quite helpful in highlighting the problem. TL;DR -- originally I intended it to be a generator but that's over-engineered. Looks good! So, two changes here: Covariant types make sense -- this is a pretty clear-cut case of where any subclass of V would work. Re: iterable -- generator was implemented by design (although not strictly necessary). Specifically, the future of this feature intends to allow more fine-grained pipelining for streaming results -- the send/yield from of a generator would be critical there. The problem is that python has no builtin protocol for All that said, we haven't actually made use of the fact that it's a generator, and we could always have another type (E.G. Mind adding a few comments on the type? Also while you're working on this, maybe we should change the name of Appreciate this, and the chance to dig into python's type system! |
Ah! So you were thinking about streaming via I feel your frustrations with python's type system - I have been using it pretty heavily over the last 3-4 years (I work with a lot of C# people and that is the only way to get them involved with python) but I still bump into rough paths all the time - like no builtin protocol for Generator, which I have seen before, but definitely did not remember. Anyway, let me add those comments and update the type variable names - I decided to go with your suggestions for the names. Note that I also updated the commented out |
Yep, I agree on the way to proceed. I'm just that weird one hoping for true compiled python at some point 😆 Appreciate the comments + changes + in-depth thoughts! This looks good, merging! |
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.
Thank you!
Attempts to fix #1114 by introducing structural subtyping for
Parallelizable
andCollect
.Changes
Both
Parallelizable
andCollect
were converted to generic protocols (vice abstract classes). The functionis_parallelizable_type
was also updated because generic protocols are not runtime checkable viaissubclass
- the function now checks the origin type viatyping.get_origin
.How I tested this
As mentioned in #1114, I was having issues running the full test suite locally on my Windows 11 machine, but I was able to run all the tests where
Parallelizable
is used, that includes the following folders:./tests/execution/
./tests/function_modifiers/
./tests/resources/
Notes
I didn't find any usage of
is_parallelizable_type
in the codebase. Is this intended for a future feature?Checklist