-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Projects who wish to depend on AutoGraph to implement their own operator overloading often need to duplicate code from AutoGraph and/or patch existing objects from the library. A clean interface for other projects to customize the behaviour of AutoGraph or provide their own implementations of operators would be beneficial.
A few examples where such issues arise:
- the
_TRANSPILERglobal in autograph/impl/api:
The global instance of the AST transformer is useful in order to benefit from caching. However, projects may supply their own instance or subclass the existing implementation to customize behaviour (e.g. to supply custom operators to theag__.namespace).
The problem arises whenever this variable is directly referenced in AG code, for example_convert_actualwhich is invoked from the theconverted_callfunction. Patching_TRANSPILERor re-implementingconverted_callis thus required. - the
CONVERSION_RULESglobal in autograph/core/config:
This variable defines rules to avoid converting functions from certain packages, which is accessed by theis_allowlistedfunction (also invoked inconverted_call).
Projects may wish to extend the existing list, requiring to patchCONVERSION_RULESor re-implementingis_allowlistedandconverted_call. - the
BUILTIN_FUNCTIONS_MAPglobal in autograph/operators/py_builtins:
This map is used to overload Python builtins such asrange,len,enumerate,print, etc. Unfortunately, this overloading is not done via the AST transformer, which normally transforms AST nodes into operators of theag__.namespace (for which custom implementations can be provided). Instead, the operators are overloaded directly in theconverted_callfunction, by referencing this map.
Providing custom implementations for builtins thus requires patchingBUILTIN_FUNCTIONS_MAPor re-implementingconverted_call.
Note that the converted_call function is itself marked with a TODO to implement it as a Call operator, in the same manner as all other overloaded operators. Implementing the operator in a way that components such as conversion rules, caching, builtins, etc. could be reused would be advantageous.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels