You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/08/07 18:32:09 UTC

[GitHub] [airflow] coufon commented on a change in pull request #5701: [AIRFLOW-5088][AIP-24] Add DAG serialization using JSON

coufon commented on a change in pull request #5701: [AIRFLOW-5088][AIP-24] Add DAG serialization using JSON
URL: https://github.com/apache/airflow/pull/5701#discussion_r311701670
 
 

 ##########
 File path: airflow/www/utils.py
 ##########
 @@ -374,6 +376,30 @@ def get_chart_height(dag):
     return 600 + len(dag.tasks) * 10
 
 
+def get_python_source(x: Union[Callable, str]) -> str:
+    """
+    Helper function to get Python source (or not), preventing exceptions
+    """
+    if isinstance(x, str):
+        return x
+    source_code = None
+    if isinstance(x, functools.partial):
+        source_code = inspect.getsource(x.func)
+    if source_code is None:
+        try:
+            source_code = inspect.getsource(x)
+        except TypeError:
+            pass
+    if source_code is None:
+        try:
+            source_code = inspect.getsource(x.__call__)
 
 Review comment:
   This fn was copied from Airflow 1.10.4. It was removed from master.
   https://github.com/apache/airflow/blob/1.10.4/airflow/www/utils.py#L407
   
   I did a test to confirm it is for a class that implements __call__:
   import inspect
   
   class A:
     def __call__(self, x):
       return x+1
   
   a = A()
   print(inspect.getsource(a.__call__)) # it works
   print(inspect.getsource(a)) # it does not

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services