LWN: Comments on "Corner cases and exception types" https://lwn.net/Articles/796012/ This is a special feed containing comments posted to the individual LWN article titled "Corner cases and exception types". en-us Sun, 31 Aug 2025 04:07:48 +0000 Sun, 31 Aug 2025 04:07:48 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Corner cases and exception types https://lwn.net/Articles/797211/ https://lwn.net/Articles/797211/ nevyn <blockquote> So how would you rewrite the "filtered_data" example? It's plenty concise for me.</blockquote> Which is: <pre> filtered_data = [y for x in data if (y := f(x)) is not None] </pre> ...the obvious simple choice is: <pre> # Just iterate data and return the value we want... filtered_data = [x for x in iter_f(data) if x is not None] </pre> ...which leads to the even better version: <pre> # Get a list of filtered values we want... filtered_data = list_filter_f(data) </pre> ...the original idea behind python wasn't to cram everything on a single line to win perl golf competitions. Sun, 25 Aug 2019 22:43:11 +0000 Corner cases and exception types https://lwn.net/Articles/796979/ https://lwn.net/Articles/796979/ nybble41 <pre>filtered_data = [y for y in map(f, data) if y is not None]</pre> Thu, 22 Aug 2019 16:34:38 +0000 Corner cases and exception types https://lwn.net/Articles/796879/ https://lwn.net/Articles/796879/ smurf <div class="FormattedComment"> So how would you rewrite the "filtered_data" example? It's plenty concise for me.<br> </div> Wed, 21 Aug 2019 20:27:38 +0000 Corner cases and exception types https://lwn.net/Articles/796559/ https://lwn.net/Articles/796559/ robert_s <div class="FormattedComment"> While I can see its use in `if` statements, its use in comprehensions seems to encourage an extremely confusing approach, mutating state in the middle of comprehensions. The power and clarity of comprehension statements comes from their use as functional, pure constructs. All of the examples I've seen of the walrus operator used in comprehensions are confusing at best.<br> </div> Sun, 18 Aug 2019 12:12:55 +0000 Corner cases and exception types https://lwn.net/Articles/796206/ https://lwn.net/Articles/796206/ nivedita76 <div class="FormattedComment"> The instances that are being turned into errors don’t make sense. It’s not banning := inside a comprehension, it’s banning it when you try to overwrite an iteration variable with it.<br> </div> Wed, 14 Aug 2019 16:03:37 +0000 Corner cases and exception types https://lwn.net/Articles/796205/ https://lwn.net/Articles/796205/ nivedita76 <div class="FormattedComment"> The leaking out is intentional. The PEP gives examples where it’s useful.<br> </div> Wed, 14 Aug 2019 16:01:52 +0000 Corner cases and exception types https://lwn.net/Articles/796141/ https://lwn.net/Articles/796141/ rsidd <div class="FormattedComment"> [replying to myself, sorry] However, this leaking would seem to be a bug in the implementation of := at the language level, not a bug by the programmer. As I understand it, it is very hard to fix in the cpython reference implementation. But therefore turning it into a programming bug seems wrong, and considerably reduces the usefulness of the operator (IMO). <br> </div> Wed, 14 Aug 2019 09:12:49 +0000 Corner cases and exception types https://lwn.net/Articles/796142/ https://lwn.net/Articles/796142/ agateau <div class="FormattedComment"> What surprises me here is that the new variable is available in the outer scope. I would expect whatever variable is defined in a comprehension list to stay in the comprehension list.<br> </div> Wed, 14 Aug 2019 09:12:47 +0000 Corner cases and exception types https://lwn.net/Articles/796140/ https://lwn.net/Articles/796140/ rsidd <div class="FormattedComment"> Interestingly, in python2 the variable inside a comprehension does leak out. This has bitten me a few times. For example, typing "[0 for i in range(5)]" will set the variable i=4 in python2, but not in python3. <br> </div> Wed, 14 Aug 2019 09:08:18 +0000 Corner cases and exception types https://lwn.net/Articles/796129/ https://lwn.net/Articles/796129/ xanni <div class="FormattedComment"> I disagree. I find that it brings considerable value that more than justifies the added complexity. It's one of the features present in other languages that I have long missed in Python and I'm very pleased to see it added.<br> </div> Wed, 14 Aug 2019 01:56:36 +0000 Corner cases and exception types https://lwn.net/Articles/796117/ https://lwn.net/Articles/796117/ Cyberax <div class="FormattedComment"> Just remove the walrus operator entirely. It provides close to no improvements but adds complexity.<br> </div> Tue, 13 Aug 2019 21:49:16 +0000