Hacker News new | ask | show | jobs
by OJFord 1458 days ago
As of 3.10, the walrus operator is your friend if you really want to name to explain:

    return cached_foobar := cache.get("foobar").data
1 comments

Wouldn’t this throw an attribute error if cache.get didn’t return an object with .data?
Yes, just as it would if you made the assignment on a line previous to the return statement.

It would also error if there was no 'cache' in scope, and anything else you can imagine.