You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2021/11/02 07:44:03 UTC

[spark] branch master updated: [SPARK-37156][PYTHON] Inline type hints for python/pyspark/storagelevel.py

This is an automated email from the ASF dual-hosted git repository.

gurwls223 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 73e8628  [SPARK-37156][PYTHON] Inline type hints for python/pyspark/storagelevel.py
73e8628 is described below

commit 73e8628f48db3f17a39f2154b54cbdea3d31e92c
Author: dchvn <dg...@viettel.com.vn>
AuthorDate: Tue Nov 2 16:43:17 2021 +0900

    [SPARK-37156][PYTHON] Inline type hints for python/pyspark/storagelevel.py
    
    ### What changes were proposed in this pull request?
    Inline type hints for python/pyspark/storagelevel.py
    
    ### Why are the changes needed?
    We can take advantage of static type checking within the functions by inlining the type hints.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    Existing tests
    
    Closes #34437 from dchvn/SPARK-37156.
    
    Authored-by: dchvn <dg...@viettel.com.vn>
    Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
 python/pyspark/storagelevel.py  | 25 +++++++++++++++++++++---
 python/pyspark/storagelevel.pyi | 43 -----------------------------------------
 2 files changed, 22 insertions(+), 46 deletions(-)

diff --git a/python/pyspark/storagelevel.py b/python/pyspark/storagelevel.py
index ecf8e5c..51fdebd 100644
--- a/python/pyspark/storagelevel.py
+++ b/python/pyspark/storagelevel.py
@@ -17,6 +17,8 @@
 
 __all__ = ["StorageLevel"]
 
+from typing import ClassVar
+
 
 class StorageLevel(object):
 
@@ -29,18 +31,35 @@ class StorageLevel(object):
     formats.
     """
 
-    def __init__(self, useDisk, useMemory, useOffHeap, deserialized, replication=1):
+    DISK_ONLY: ClassVar["StorageLevel"]
+    DISK_ONLY_2: ClassVar["StorageLevel"]
+    DISK_ONLY_3: ClassVar["StorageLevel"]
+    MEMORY_ONLY: ClassVar["StorageLevel"]
+    MEMORY_ONLY_2: ClassVar["StorageLevel"]
+    MEMORY_AND_DISK: ClassVar["StorageLevel"]
+    MEMORY_AND_DISK_2: ClassVar["StorageLevel"]
+    OFF_HEAP: ClassVar["StorageLevel"]
+    MEMORY_AND_DISK_DESER: ClassVar["StorageLevel"]
+
+    def __init__(
+        self,
+        useDisk: bool,
+        useMemory: bool,
+        useOffHeap: bool,
+        deserialized: bool,
+        replication: int = 1,
+    ):
         self.useDisk = useDisk
         self.useMemory = useMemory
         self.useOffHeap = useOffHeap
         self.deserialized = deserialized
         self.replication = replication
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         return "StorageLevel(%s, %s, %s, %s, %s)" % (
             self.useDisk, self.useMemory, self.useOffHeap, self.deserialized, self.replication)
 
-    def __str__(self):
+    def __str__(self) -> str:
         result = ""
         result += "Disk " if self.useDisk else ""
         result += "Memory " if self.useMemory else ""
diff --git a/python/pyspark/storagelevel.pyi b/python/pyspark/storagelevel.pyi
deleted file mode 100644
index 2eb0585..0000000
--- a/python/pyspark/storagelevel.pyi
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-from typing import ClassVar
-
-class StorageLevel:
-    DISK_ONLY: ClassVar[StorageLevel]
-    DISK_ONLY_2: ClassVar[StorageLevel]
-    MEMORY_ONLY: ClassVar[StorageLevel]
-    MEMORY_ONLY_2: ClassVar[StorageLevel]
-    DISK_ONLY_3: ClassVar[StorageLevel]
-    MEMORY_AND_DISK: ClassVar[StorageLevel]
-    MEMORY_AND_DISK_2: ClassVar[StorageLevel]
-    OFF_HEAP: ClassVar[StorageLevel]
-
-    useDisk: bool
-    useMemory: bool
-    useOffHeap: bool
-    deserialized: bool
-    replication: int
-    def __init__(
-        self,
-        useDisk: bool,
-        useMemory: bool,
-        useOffHeap: bool,
-        deserialized: bool,
-        replication: int = ...,
-    ) -> None: ...

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