Wraps either a dummy MethodType or a converted AutoGraph function.
(*args, **kwargs)
| 2636 | |
| 2637 | weak_bound_method_wrapper = None |
| 2638 | def bound_method_wrapper(*args, **kwargs): |
| 2639 | """Wraps either a dummy MethodType or a converted AutoGraph function.""" |
| 2640 | # __wrapped__ allows AutoGraph to swap in a converted function. |
| 2641 | strong_bound_method_wrapper = weak_bound_method_wrapper() |
| 2642 | wrapped_fn = strong_bound_method_wrapper.__wrapped__ |
| 2643 | |
| 2644 | if wrapped_fn is strong_bound_method_wrapper.__original_wrapped__: |
| 2645 | # If __wrapped__ was not replaced, then call original_function. |
| 2646 | # TODO(mdan): For better consistency, use the wrapper's call(). |
| 2647 | wrapped_fn = original_function.python_function |
| 2648 | if tf_inspect.ismethod(wrapped_fn): |
| 2649 | wrapped_fn = six.get_unbound_function(wrapped_fn) |
| 2650 | return wrapped_fn(weak_instance(), *args, **kwargs) |
| 2651 | |
| 2652 | # If __wrapped__ was replaced, then it is always an unbound function. |
| 2653 | # However, the replacer is still responsible for attaching self properly. |
| 2654 | # TODO(mdan): Is it possible to do it here instead? |
| 2655 | return wrapped_fn(*args, **kwargs) |
| 2656 | weak_bound_method_wrapper = weakref.ref(bound_method_wrapper) |
| 2657 | |
| 2658 | # pylint: disable=protected-access |
nothing calls this directly
no test coverage detected