home.social

#walrusoperator — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #walrusoperator, aggregated by home.social.

  1. Just wrote the first blog article in 6 years on my personal blog. 🎉

    Handling Paginated API Responses with the Walrus Operator

    joeriksson.se/blog/handling-pa

  2. Encapsulating the atrocity of umask handling with Python's walrus operator:

    os.umask(current_umask := os.umask(0))

    This isn't clearly *better*, but at least it's clearly shorter. Without `:=`, we'd need two lines:

    current_umask = os.umask(0)
    os.umask(current_umask)

    Note: The awkwardness is a necessary consequence of how POSIX handles umask. Also, neither version is threadsafe.

    #Python #WalrusOperator #umask

  3. would you use the #WalrusOperator?

     if test_fit(i, j, s) or test_fit(i, j, s := 1):
    fill_grid(i, j, s)

    or make it a bit longer like this

    if test_fit(i, j, s):
    fill_grid(i, j, s)
    elif test_fit(i, j, 1):
    fill_grid(i, j, 1)

    ? #Python