3 ms·
> Here we have a problem, for subscription does None mean don't change or remove subscription I read this like 10 times and I still dont understand this mess o
by flysand7 2y ago
> Here we have a problem, for subscription does None mean don't change or remove subscription
I read this like 10 times and I still dont understand this mess of grammar. Am I having a fucking stroke rn?
- roywiggins 2y agofor "subscription", does `None` mean "don't change", or "remove subscription"?
- Ericson2314 2y agoQuoting, important when (meta-)programming and in natural language!
- dan-robertson 2y agoI’m going to send you some json to update your object – an HTTP PATCH request. There are three possible updates I might want to make to the subscription field: - change it to a new value - set it to None - leave it as-is In the json the first two options are specified by sending an object with a "subscription" field, either set to a string or to null. The third case is expressed by omitting the field. The OP asks how all three cases could be represented in python, and points out that one could not use subscription=None to represent both case 2 and 3 above.
- RHSeeger 2y agoIf you need to be able to represent what looks like a tree of data set - no value - new value do_no_set (sorry about the horrible tree) then it seems like you should represent the data like that. Pass in action (set/ignore) and value (value for set, no value for ignore). Or even (set/unset/ignore), which allows you to have some sanity checking that, if the action is set, an actual value is provided (and vice versa for unset).
- syockit 2y agoBetter punctuated: > Here we have a problem: for subscription, does None mean don't change or remove subscription?
- gorgoiler 2y agoHere we have a problem: If the “subscription” part of the “patch” data-structure is set to “None” it is impossible to tell if this means: 1/ leave the “subscription” unchanged; or 2/ set the “subscription” to None. — You could solve this by requiring that a subscription is either a value or some other sentinel value meaning “not subscribed”: from typing import Union class T: pass NotSubscribed = T() Subscription = Union[int, T] def f(s: Subscription): pass f(44) f(NotSubscribed) f(None) # wrong Is there a better way of doing this? (One that isn’t just “use Haskell” :)