-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PEP 798: Add Discussion of Alternative GenExp Semantics #4547
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
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
Just a heads-up that I probably won't have my updates in tonight, since I'm still going back and forth in my head about what the right decision is here... In case it's of interest, here's what I'm currently thinking:
So I think I might actually be slowly convincing myself that the option you voted for in the poll might be the right choice 😄. That way we could use But, tl;dr: I'm going to need to think about this a bit more (and probably follow up in the Discourse thread, too). |
|
There's no hurry! The only sort-of-deadline is the Python 3.15 feature freeze next May, and we have plenty of time before that. Here's some thoughts from me, but I don't have firm views either.
With PEP 798 unpacking and >>> def make_gen(i):
... val = yield "input:"
... yield val * i
...
>>> g = (*make_gen(i) for i in range(5, 10))
>>>
>>> g.send(None)
'input:'
>>> g.send(1)
5
>>> g.send(None)
'input:'
>>> g.send(3)
18
>>> g.send(None)
'input:'
>>> g.send(4)
28Well, not that practically useful, but maybe you'd be able to come up with a way to use this that is actually good for something useful. This provides an argument that it's reasonable to go with |
|
Thanks for the input! I agree on all fronts. And actually, the need to repeatedly send |
I think you don't actually need to send Nones for every one of them, e.g. this worked: >>> g.send(4)
28
>>> g.send(42)
'input:'
>>> g.send(43)
344But it's definitely a complicated interface to work with. |
Ah, sorry, yes, but every so often one thing that you send will effectively be ignored, right? That is, the output above would have been the same with any other object in place of |
|
True, though I could have gotten it out if I had made the inner generator do something with the result of the second yield. |
|
Oh, interesting. Yeah, you're right. Sorry; I was misunderstanding what was actually happening there! |
|
After a lot of waffling back and forth, I decided to roll back the semantic changes here. I do think there's limited utility in delegating to subgenerators in this context, but I'm not sure that that's worth excluding it as a possibility. No rush at all, but if you don't mind taking a look at the updated version sometime, @JelleZijlstra, feedback would be very welcome :) |
JelleZijlstra
left a comment
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.
Thanks, spotted one typo.
|
Thanks! I fixed that one and another typo I found, and I added one more sentence to the Backwards Compatibility section trying to say that even though we're setting ourselves up for a backwards-incompatible change in the future, it's likely not a big deal. |
|
It might be worth adding some more detailed discussion of the actual change in behavior you get between using |
|
Good call. I'll see if I can add a small example today. I'm a little worried that the PEP is already quite long for proposing a relatively small change, but I agree that that would be a good addition. |
|
It might be a good fit for an appendix, like the two I put in PEP-800. |
|
Sorry to be so slow on this, @JelleZijlstra! I just added an appendix with some examples of the differences between |
JelleZijlstra
left a comment
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!
|
Thanks, Jelle! |
The main change here is adjusting the proposed semantics of unpacking in generator expressions and adding a section briefly outlining the pros and cons of the alternatives, but I also:
📚 Documentation preview 📚: https://pep-previews--4547.org.readthedocs.build/