Compiles a function call inline. For internal use only. Args: f: The function to convert. options: converter.ConversionOptions args: Tuple, the original positional arguments of f kwargs: Dict, the original keyword arguments of f caller_fn_scope: Optional[function_wrappers.F
(f, options, args, kwargs, caller_fn_scope=None)
| 363 | |
| 364 | |
| 365 | def converted_call(f, options, args, kwargs, caller_fn_scope=None): |
| 366 | """Compiles a function call inline. |
| 367 | |
| 368 | For internal use only. |
| 369 | |
| 370 | Args: |
| 371 | f: The function to convert. |
| 372 | options: converter.ConversionOptions |
| 373 | args: Tuple, the original positional arguments of f |
| 374 | kwargs: Dict, the original keyword arguments of f |
| 375 | caller_fn_scope: Optional[function_wrappers.FunctionScope], the function |
| 376 | scope of the converted function in which this call was originally made. |
| 377 | |
| 378 | Returns: |
| 379 | Any, the result of executing a possibly-converted `f` with the given |
| 380 | arguments. |
| 381 | """ |
| 382 | logging.log(1, 'Converted call: %s\n args: %s\n kwargs: %s\n', f, args, |
| 383 | kwargs) |
| 384 | |
| 385 | if conversion.check_cached_unconverted(f, options): |
| 386 | return _call_unconverted(f, args, kwargs, options, False) |
| 387 | |
| 388 | if inspect_utils.isbuiltin(f): |
| 389 | if f is eval: |
| 390 | return py_builtins.eval_in_original_context(f, args, caller_fn_scope) |
| 391 | if f is super: |
| 392 | return py_builtins.super_in_original_context(f, args, caller_fn_scope) |
| 393 | if kwargs: |
| 394 | return py_builtins.overload_of(f)(*args, **kwargs) |
| 395 | else: |
| 396 | return py_builtins.overload_of(f)(*args) |
| 397 | |
| 398 | # TODO(mdan): Clean up the naming inconsistency. |
| 399 | if hasattr(f, 'autograph_info__') or hasattr(f, '__ag_compiled'): |
| 400 | logging.log(2, 'Permanently whitelisted: %s: already converted', f) |
| 401 | return _call_unconverted(f, args, kwargs, options) |
| 402 | |
| 403 | # TODO(b/122265385): Remove this bypass. |
| 404 | if (_is_known_loaded_type(f, 'wrapt', 'FunctionWrapper') or |
| 405 | _is_known_loaded_type(f, 'wrapt', 'BoundFunctionWrapper')): |
| 406 | logging.warn( |
| 407 | 'Entity {} appears to be decorated by wrapt, which is not yet supported' |
| 408 | ' by AutoGraph. The function will be called without transformation.' |
| 409 | ' You may however apply AutoGraph before the decorator.'.format(f)) |
| 410 | logging.log(2, 'Permanently whitelisted: %s: wrapt decorated', f) |
| 411 | return _call_unconverted(f, args, kwargs, options) |
| 412 | |
| 413 | if _is_known_loaded_type(f, 'functools', '_lru_cache_wrapper'): |
| 414 | logging.log(2, 'Permanently whitelisted: %s: lru_cache', f) |
| 415 | return _call_unconverted(f, args, kwargs, options) |
| 416 | |
| 417 | # Constructors are permanently whitelisted. |
| 418 | # TODO(mdan): Toggle as experimental feature instead. |
| 419 | # TODO(b/124016764): Remove this limitation. |
| 420 | if tf_inspect.isclass(f): |
| 421 | logging.log(2, 'Permanently whitelisted: %s: constructor', f) |
| 422 | return _call_unconverted(f, args, kwargs, options) |
no test coverage detected