4 ms·
> I'm still looking forward to using assignment expressions for testing my re.match() objects. The fact that this is the go-to example that everybody is using
by DonaldPShimoda 7y ago
> I'm still looking forward to using assignment expressions for testing my re.match() objects.
The fact that this is the go-to example that everybody is using in justifying the introduction of the assignment expression convinces me that the real problem lies with the re module's API.
(To be clear: I will also be using assignment expressions for this case, but I don't think assignment expressions are really in line with the overall design of Python.)
- fjp 7y agore's API sucks but I'm looking forward to safe dictionary access with assignment as well. No more if my_map.get(key) is not None: // do something with my_map[key]
- DonaldPShimoda 7y agoHere the "better" solution (imo) would be support for pattern matching: match my_map.get(key): case None: // do thing (or nothing, i.e., pass) case Some(val): // do other thing Scala seems to have figured out how to get pattern matching over arbitrary data (i.e., not statically-defined algebraic datatypes). I'd like to see this come to Python. (Normally I'd fight for pattern matching to always provide static type safety guarantees, but in Python it seems completely reasonable to omit such checks.) EDIT: But you're absolutely right that this is a place where assignment expressions will be used regularly, so thank you for pointing that out!