This is an automated email from the ASF dual-hosted git repository.
zhengruifeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 30bc0b63bb3d [SPARK-57233][PYTHON] Fix type hint in SparkSession.sql()
30bc0b63bb3d is described below
commit 30bc0b63bb3dc9f588b074202bc43a47d3ec018b
Author: Jonathan Dayton <[email protected]>
AuthorDate: Thu Jun 4 21:58:38 2026 +0800
[SPARK-57233][PYTHON] Fix type hint in SparkSession.sql()
### What changes were proposed in this pull request?
Complete the type hint for `SparkSession.sql()`'s `args` param for the
"positional parameters" case (`List` becomes `List[Any]`). This creates parity
with the existing type hint for the "named parameters" case (`Dict[str, Any]`).
### Why are the changes needed?
Pylance interprets a collection type without a subscript as `Unknown`. When
strict type checking mode is enabled, `Unknown` types raise an error:
<img width="1048" height="161" alt="image"
src="https://github.com/user-attachments/assets/bbf7e0b6-2cef-4ca9-bc88-fe5e1331e48c"
/>
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Verified locally in VSCode that completing this type hint removes the
type-checker error:
<img width="308" height="72" alt="image"
src="https://github.com/user-attachments/assets/d051d324-a233-414b-99fa-848305e560f7"
/>
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #56251 from jdayton3/spark-sql-func-type-hint.
Authored-by: Jonathan Dayton <[email protected]>
Signed-off-by: Ruifeng Zheng <[email protected]>
---
python/pyspark/sql/connect/session.py | 2 +-
python/pyspark/sql/session.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/pyspark/sql/connect/session.py
b/python/pyspark/sql/connect/session.py
index 20d237b1c958..d538e427e51c 100644
--- a/python/pyspark/sql/connect/session.py
+++ b/python/pyspark/sql/connect/session.py
@@ -800,7 +800,7 @@ class SparkSession:
def sql(
self,
sqlQuery: str,
- args: Optional[Union[Dict[str, Any], List]] = None,
+ args: Optional[Union[Dict[str, Any], List[Any]]] = None,
**kwargs: Any,
) -> "ParentDataFrame":
_args = []
diff --git a/python/pyspark/sql/session.py b/python/pyspark/sql/session.py
index a1fd6ba72bef..c36260b9d13e 100644
--- a/python/pyspark/sql/session.py
+++ b/python/pyspark/sql/session.py
@@ -1756,7 +1756,7 @@ class SparkSession(SparkConversionMixin):
return self.createDataFrame([], schema)
def sql(
- self, sqlQuery: str, args: Optional[Union[Dict[str, Any], List]] =
None, **kwargs: Any
+ self, sqlQuery: str, args: Optional[Union[Dict[str, Any], List[Any]]]
= None, **kwargs: Any
) -> "ParentDataFrame":
"""Returns a :class:`DataFrame` representing the result of the given
query.
When ``kwargs`` is specified, this method formats the given string by
using the Python
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]