Python: Can I get None's attribute from the descriptor's __get__?

23 Views Asked by At

I have this callable object bool_getter := vars(type(None))["__bool__"].__get__ (of type types.MethodWrapperType). Is there a way to make this bool_getter return None's method None.__bool__ by calling it? I didn't figure it out after trying a few obvious choices. (The value of None.__bool__ is not identical every time the expression is evaluated, so I want bool_getter to return not the identical but just an equal object.)

In case the question didn't make full sense to you, please consider doing one of the following things.

  1. Please show me a way to construct an iterable args and a mapping kwargs such that you get an object value := bool_getter(*args, **kwargs) successfully, and that value will be equal to boolNone := None.__bool__. That is, type(value) should be type(boolNone), namely, types.MethodWrapperType and value == boolNone must be True. (In my experience, boolNone always satisfies boolNone == None.__bool__.)

  2. If that's impossible to do, please show me how you can tell it.

0

There are 0 best solutions below