You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/07/12 09:02:54 UTC

[GitHub] [spark] HyukjinKwon commented on a diff in pull request #37117: [SPARK-39714][PYTHON] Try to fix the mypy annotation tests

HyukjinKwon commented on code in PR #37117:
URL: https://github.com/apache/spark/pull/37117#discussion_r918728918


##########
python/pyspark/ml/util.py:
##########
@@ -536,10 +536,8 @@ def __get_class(clazz: str) -> Type[RL]:
         """
         parts = clazz.split(".")
         module = ".".join(parts[:-1])
-        m = __import__(module)
-        for comp in parts[1:]:
-            m = getattr(m, comp)
-        return m
+        m = __import__(module, fromlist=[parts[-1]])
+        return getattr(m, parts[-1])

Review Comment:
   Hm, I think this changes the semantic. Previously, it returned the left-most import but not it returns right-most package. For example,
   
   ```python
   >>> __import__("pyspark", fromlist=['sql'])
   <module 'pyspark' from '/.../spark/python/pyspark/__init__.py'>
   >>> m = __import__("pyspark")
   >>> getattr(m, "sql")
   <module 'pyspark.sql' from '/.../spark/python/pyspark/sql/__init__.py'>
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org