this post was submitted on 12 Apr 2025
195 points (90.1% liked)

Technology

69109 readers
3134 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments

Maybe, but that serves as a very valuable teaching opportunity about the concept of "empty" is in Python. It's pretty intuitive IMO, and it can make a lot of things more clear once you understand that.

That said, larger projects should be using type hints everywhere, and that should make the intention here painfully obvious:

def do_work(foo: list | None):
    if not foo:
        ... handle empty list ...
    ...

That's obviously not a boolean, but it's being treated as one. If the meaning there isn't obvious, then look it up/ask someone about Python semantics.

I'm generally not a fan of learning a ton of jargon/big frameworks to get the benefits of more productivity (e.g. many design patterns are a bit obtuse IMO), but learning language semantics that are used pretty much everywhere seems pretty reasonable to me. And it's a lot nicer than doing something like this everywhere:

if foo is None or len(foo) == 0: