I would like to create a class that inherites from None
.
Tried this:
class InvalidKeyNone(None):
pass
but that gives me:
TypeError: Error when calling the metaclass bases
cannot create 'NoneType' instances
What would be the correct solution that gives me a type that behaves exactly like None
but which I can type test?
foo = InvalidKeyNone()
print(type(foo))
>>> InvalidKeyNone
[EDIT]
I want to do this because I am creating a selection scheme on Python datastructures:
bar = select(".foo.bar.[1].x", {"foo":{"bar":[{"x":1}, {"x":2}], "baz":3})
print(bar)
>> 2
And I want to be able to determine whether I get a None because the selected value is None or because the key was not found. HOWEVER it must return a (ducktyped) None that behaves exactly like a None. No exceptions or custom type returning here.
[EDIT]
Ok, so the consensus is: can't be done. Which although unsatisfactory is a valid answer. Since I really want the default behavior to have it return a None when the key is not present I think I will have the select eat a param to switch to exception throwing when appropriate. Thanks.