ashb commented on pull request #8962:
URL: https://github.com/apache/airflow/pull/8962#issuecomment-632623113


   Do copy what I put in slack, Thanks to Stackoverflow I've got a way of 
having `from airflow import task` be callable, and still work as a submodule:
   
   ```diff
   diff --git airflow/task/__init__.py airflow/task/__init__.py
   index 114d189da..0b15c9a8c 100644
   --- airflow/task/__init__.py
   +++ airflow/task/__init__.py
   @@ -16,3 +16,20 @@
    # KIND, either express or implied.  See the License for the
    # specific language governing permissions and limitations
    # under the License.
   +
   +import sys
   +import types
   +
   +
   +class CallableModule(types.ModuleType):
   +    def __init__(self):
   +        types.ModuleType.__init__(self, __name__)
   +        self.__dict__.update(sys.modules[__name__].__dict__)
   +
   +    __all__ = list(set(vars().keys()) - {'__qualname__'})   # for python 2 
and 3
   +
   +    def __call__(self, *args, **kwargs):
   +        from airlfow.decorators import task
   +        return task(*args, **kwargs)
   +
   +sys.modules[__name__] = CallableModule()
   ```
   
   This works in Py 2.7, 3.7 and 3.8 (versions I have easy access to).
   
   The main question is: do we want to support that? Is this "hack" worth it, 
and do IDEs get massively confused by this?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to