3 ms·
I am quite concerned about the kinds of PEPs that come up lately (edit: I now noticed it's three years old). Python is drifting farther and farther away from it
by thijsvandien 8y ago
I am quite concerned about the kinds of PEPs that come up lately (edit: I now noticed it's three years old). Python is drifting farther and farther away from its nature and strength. The amount of complexity is constantly going up and I don't think it's a good thing. Please let this language be what is is.
A small amount of boilerplate in cases like this is fine and motivates you to restructure the code rather than hiding the mess in this way.
Why write
data = data if data is not None else []
as
data = data ?? []
if you could simply use
data = data or []
which already exists and for all intents and purposes should achieve the same thing?
Need to make sure you can always append to something so you can drop some conditions?
lst = get_log_list()
lst?.append('A log message')
would have been
lst = get_log_list() or []
lst.append('A log message')
right now. In terms of reconsidering the structure of your code, I wonder if a log list not existing or being empty is a meaningful distinction. Perhaps it could return an empty list to begin with.
Even
libpaths = libpaths?.split(":") ?? []
is fairly easy to deal with already if you absolutely want to it be short:
libpaths = (libpaths or '').split(":")
Then again, if it is going to be treated as a string, why would it ever be None rather than an empty string? Is that distinction important? Being able to shove it under the rug by sprinkling some question marks over it, allows you to never stop and wonder about that, when in fact, you should.
- chatnati 8y agoAdding to this comment - data = data if data is not None else [] (is) data = data if data else [] (is) data = data or [] which means you either did: data = [] (or) data = None The line above is wrong - you always define your variables to match your structures properly during your __init__. For all intents and purposes, [] is the same as None when you're attempting a true/false if statement (of course it's not 100% but I'm trying to make the point). Having a Null coalescing operator is a cheap and crappy way to escape proper variable definition and proper statement resolution, and it means you don't understand what your code actually does when reaching the compiler, or behavior in the memory. PEP 505 should be rejected.
- emblaegh 8y ago> data or [] Unfortunately this kind of conditional assignment does not work if `data` is a numpy array. This arguably more numpy's fault than python's, though it is a mildly infuriating when it happens.