3 ms·
But this is potentially dangerous. E.g.: dict.setObjectForKey(@"b", @"a"); assert(dict.containsObjectForKey[@"a"]); A bit tangential related to the ar
by albertzeyer 5y ago
But this is potentially dangerous. E.g.:
dict.setObjectForKey(@"b", @"a");
assert(dict.containsObjectForKey[@"a"]);
A bit tangential related to the article:
In Python, I often found that it is helpful to also have a separate "None"-like type despite None, which I called NotSpecified. Often in functions you have sth like:
def func(opt: int = None):
if opt is None:
opt = get_default_opt()
...
This works fine when you now that opt should not be None here. However, if None is allowed for opt and causes some other specific behavior, I now do:
def func(opt: Optional[int] = NotSpecified):
if opt is NotSpecified:
opt = get_default_opt()
...
This is also useful for dicts:
my_dict.get("foo", NotSpecified)