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

Technology

68772 readers
4722 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
(page 2) 50 comments
sorted by: hot top controversial new old
[–] Archr@lemmy.world 1 points 2 days ago

I haven't read the article. But I'd assume this is for the same reason that not not string is faster than bool(string). Which is to say that it has to do with having to look up a global function rather than a known keyword.

[–] antlion@lemmy.dbzer0.com 7 points 3 days ago (2 children)

Could also compare against:

if not len(mylist)

That way this version isn’t evaluating two functions. The bool evaluation of an integer is false when zero, otherwise true.

That's worse. IMO, solve this problem with two things:

  • type hint mylist as list | None or just list
  • use if not mylist:

The first documents intent and gives you static analysis tools some context to check for type consistency/compatibility, and the second shows that None vs empty isn't an important distinction here.

[–] FooBarrington@lemmy.world 4 points 3 days ago (2 children)

This is honestly the worst version regarding readability. Don't rely on implicit coercion, people.

load more comments (2 replies)
[–] knighthawk0811@lemmy.ml 7 points 4 days ago (1 children)

so these are the only 2 ways then? huge if true

load more comments (1 replies)
load more comments
view more: ‹ prev next ›