• sugar_in_your_tea@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    10 hours ago

    Why? not x means x is None or len(x) == 0 for lists. len(x) == 0 will raise an exception if x is None. In most cases, the distinction between None and [] isn’t important, and if it is, I’d expect separate checks for those (again, for explicitness) since you’d presumably handle each case differently.

    In short:

    • if the distinction between None and [] is important, have separate checks
    • if not, not x should be your default, since that way it’s a common pattern for all types