def _infer_unaryop(self, context=None):
for operand in self.operand.infer(context):<EOL><INDENT>try:<EOL><INDENT>yield operand.infer_unary_op(self.op)<EOL><DEDENT>except TypeError as exc:<EOL><INDENT>yield util.BadUnaryOperationMessage(operand, self.op, exc)<EOL><DEDENT>except AttributeError as exc:<EOL><INDENT>meth = protocols.UNARY_OP_METHOD[self.op]<EOL>if meth is None:<EOL><INDENT>bool_value = operand.bool_value()<EOL>if bool_value is not util.Uninferable:<EOL><INDENT>yield nodes.const_factory(not bool_value)<EOL><DEDENT>else:<EOL><INDENT>yield util.Uninferable<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not isinstance(operand, (bases.Instance, nodes.ClassDef)):<EOL><INDENT>yield util.BadUnaryOperationMessage(operand, self.op, exc)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>try:<EOL><INDENT>methods = dunder_lookup.lookup(operand, meth)<EOL><DEDENT>except exceptions.AttributeInferenceError:<EOL><INDENT>yield util.BadUnaryOperationMessage(operand, self.op, exc)<EOL>continue<EOL><DEDENT>meth = methods[<NUM_LIT:0>]<EOL>inferred = next(meth.infer(context=context))<EOL>if inferred is util.Uninferable or not inferred.callable():<EOL><INDENT>continue<EOL><DEDENT>context = contextmod.copy_context(context)<EOL>context.callcontext = contextmod.CallContext(args=[operand])<EOL>call_results = inferred.infer_call_result(self, context=context)<EOL>result = next(call_results, None)<EOL>if result is None:<EOL><INDENT>yield operand<EOL><DEDENT>else:<EOL><INDENT>yield result<EOL><DEDENT><DEDENT>except exceptions.AttributeInferenceError as exc:<EOL><INDENT>yield util.BadUnaryOperationMessage(operand, self.op, exc)<EOL><DEDENT>except exceptions.InferenceError:<EOL><INDENT>yield util.Uninferable<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Infer what an UnaryOp should return when evaluated.