kaxil commented on code in PR #28067:
URL: https://github.com/apache/airflow/pull/28067#discussion_r1039674466


##########
airflow/utils/module_loading.py:
##########
@@ -38,6 +40,20 @@ def import_string(dotted_path):
         raise ImportError(f'Module "{module_path}" does not define a 
"{class_name}" attribute/class')
 
 
-def as_importable_string(thing) -> str:
+def qualname(o: object) -> str:
     """Convert an attribute/class to a string importable by 
``import_string``."""
-    return f"{thing.__module__}.{thing.__name__}"
+    cls = o
+    if not isinstance(cls, type):  # instance or class
+        cls = type(cls)
+
+    name = cls.__qualname__
+    module = cls.__module__

Review Comment:
   yeah this is needed for things like below:
   
   ```python
   In [1]: import numpy
   
   In [2]: numpy.int64(2)
   Out[2]: 2
   
   In [3]: type(_2)
   Out[3]: numpy.int64
   
   In [4]: type(_2).__qualname__
   Out[4]: 'int64'
   
   In [5]: type(_2).__module__
   Out[5]: 'numpy'
   
   In [6]: _2.__qualname__
   ---------------------------------------------------------------------------
   AttributeError                            Traceback (most recent call last)
   Input In [6], in <cell line: 1>()
   ----> 1 _2.__qualname__
   
   AttributeError: 'numpy.int64' object has no attribute '__qualname__'
   
   In [7]: _2.__module__
   ---------------------------------------------------------------------------
   AttributeError                            Traceback (most recent call last)
   Input In [7], in <cell line: 1>()
   ----> 1 _2.__module__
   
   AttributeError: 'numpy.int64' object has no attribute '__module__'
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to