Skip to content

Commit e44a99c

Browse files
authored
Cython None guards (rapidsai#497)
Closes rapidsai#492 Authors: - Mads R. B. Kristensen (https://github.com/madsbk) Approvers: - Tom Augspurger (https://github.com/TomAugspurger) - Kyle Edwards (https://github.com/KyleFromNVIDIA) URL: rapidsai#497
1 parent 5a29a5a commit e44a99c

25 files changed

+105
-114
lines changed

python/rapidsmpf/rapidsmpf/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# =================================================================================
55

6-
set(cython_modules config.pyx progress_thread.pyx rmm_resource_adaptor.pyx shuffler.pyx
7-
statistics.pyx
6+
set(cython_modules config.pyx cuda_stream.pyx progress_thread.pyx rmm_resource_adaptor.pyx
7+
shuffler.pyx statistics.pyx
88
)
99

1010
rapids_cython_create_modules(

python/rapidsmpf/rapidsmpf/buffer/packed_data.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ cdef class PackedData:
4646

4747
@classmethod
4848
def from_cudf_packed_columns(
49-
cls, PackedColumns packed_columns, Stream stream, BufferResource br
49+
cls,
50+
PackedColumns packed_columns not None,
51+
Stream stream not None,
52+
BufferResource br not None,
5053
):
5154
"""
5255
Constructs a PackedData from CudfPackedColumns by taking the ownership of the

python/rapidsmpf/rapidsmpf/buffer/resource.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cdef class BufferResource:
6161
"""
6262
def __cinit__(
6363
self,
64-
DeviceMemoryResource device_mr,
64+
DeviceMemoryResource device_mr not None,
6565
memory_available = None,
6666
periodic_spill_check = 1e-3
6767
):
@@ -177,7 +177,7 @@ cdef class LimitAvailableMemory:
177177
>>> mr = RmmResourceAdaptor(...)
178178
>>> memory_limiter = LimitAvailableMemory(mr, limit=1_000_000)
179179
"""
180-
def __init__(self, RmmResourceAdaptor mr, int64_t limit):
180+
def __init__(self, RmmResourceAdaptor mr not None, int64_t limit):
181181
self._mr = mr # Keep the mr alive.
182182
cdef cpp_RmmResourceAdaptor* handle = mr.get_handle()
183183
with nogil:

python/rapidsmpf/rapidsmpf/buffer/spill_manager.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cdef class SpillManager:
8888
self._handle = NULL
8989

9090
@classmethod
91-
def _create(cls, BufferResource br):
91+
def _create(cls, BufferResource br not None):
9292
"""Construct a SpillManager associated the specified buffer resource.
9393
9494
This shouldn't be used directly instead use `BufferResource.spill_manage)`.

python/rapidsmpf/rapidsmpf/communicator/communicator.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cdef class Logger:
5656
"""
5757
return cpp_verbosity_level(self._comm._handle)
5858

59-
def print(self, msg: str):
59+
def print(self, str msg not None):
6060
"""
6161
Logs a print message.
6262
@@ -68,7 +68,7 @@ cdef class Logger:
6868
cdef string _msg = msg.encode()
6969
cpp_log(LOG_LEVEL.PRINT, self._comm._handle, move(_msg))
7070

71-
def warn(self, msg: str):
71+
def warn(self, str msg not None):
7272
"""
7373
Logs a warning message.
7474
@@ -80,7 +80,7 @@ cdef class Logger:
8080
cdef string _msg = msg.encode()
8181
cpp_log(LOG_LEVEL.WARN, self._comm._handle, move(_msg))
8282

83-
def info(self, msg: str):
83+
def info(self, str msg not None):
8484
"""
8585
Logs an informational message.
8686
@@ -92,7 +92,7 @@ cdef class Logger:
9292
cdef string _msg = msg.encode()
9393
cpp_log(LOG_LEVEL.INFO, self._comm._handle, move(_msg))
9494

95-
def debug(self, msg: str):
95+
def debug(self, str msg not None):
9696
"""
9797
Logs a debug message.
9898
@@ -104,7 +104,7 @@ cdef class Logger:
104104
cdef string _msg = msg.encode()
105105
cpp_log(LOG_LEVEL.DEBUG, self._comm._handle, move(_msg))
106106

107-
def trace(self, msg: str):
107+
def trace(self, str msg not None):
108108
"""
109109
Logs a trace message.
110110

python/rapidsmpf/rapidsmpf/communicator/mpi.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cdef extern from "<rapidsmpf/communicator/mpi.hpp>" nogil:
1515
cpp_MPI_Communicator(libmpi.MPI_Comm comm, cpp_Options options) except +
1616

1717

18-
def new_communicator(Intracomm comm, Options options):
18+
def new_communicator(Intracomm comm not None, Options options not None):
1919
"""
2020
Create a new RapidsMPF-MPI communicator based on an existing mpi4py communicator.
2121

python/rapidsmpf/rapidsmpf/communicator/single.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cdef extern from "<rapidsmpf/communicator/single.hpp>" nogil:
1313
cpp_Single_Communicator(cpp_Options options) except +
1414

1515

16-
def new_communicator(Options options):
16+
def new_communicator(Options options not None):
1717
"""
1818
Create a new RapidsMPF single-process communicator.
1919

python/rapidsmpf/rapidsmpf/communicator/ucxx.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ from rapidsmpf.communicator.communicator import Communicator
77
from rapidsmpf.config import Options
88

99
def new_communicator(
10-
nranks: int, ucx_worker: UCXWorker, root_ucxx_address: UCXAddress, options: Options
10+
nranks: int,
11+
ucx_worker: UCXWorker | None,
12+
root_ucxx_address: UCXAddress | None,
13+
options: Options,
1114
) -> Communicator: ...
1215
def get_root_ucxx_address(comm: Communicator) -> bytes: ...
1316
def barrier(comm: Communicator) -> None: ...

python/rapidsmpf/rapidsmpf/communicator/ucxx.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def new_communicator(
8383
Rank nranks,
8484
UCXWorker ucx_worker,
8585
UCXAddress root_ucxx_address,
86-
Options options,
86+
Options options not None,
8787
):
8888
"""
8989
Create a new UCXX communicator with the given number of ranks.
@@ -121,7 +121,7 @@ def new_communicator(
121121
)
122122

123123

124-
def get_root_ucxx_address(Communicator comm):
124+
def get_root_ucxx_address(Communicator comm not None):
125125
"""
126126
Get the address of the communicator's UCXX worker.
127127
@@ -164,7 +164,7 @@ def get_root_ucxx_address(Communicator comm):
164164
assert host_port_pair # Prevent "defined but unused" error
165165

166166

167-
def barrier(Communicator comm):
167+
def barrier(Communicator comm not None):
168168
"""
169169
Execute a barrier on the UCXX communicator.
170170

python/rapidsmpf/rapidsmpf/config.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ cdef class Options:
6464
ret = self._handle.insert_if_absent(move(opts))
6565
return ret
6666

67-
def get(self, str key, *, return_type, factory):
67+
def get(self, str key not None, *, return_type, factory):
6868
"""
6969
Retrieves a configuration option by key.
7070
@@ -119,7 +119,7 @@ cdef class Options:
119119
return config_options_get.get_str(self, key, factory)
120120
return config_options_get.get_py_obj(self, key, factory)
121121

122-
def get_or_default(self, str key, *, default_value):
122+
def get_or_default(self, str key not None, *, default_value):
123123
"""
124124
Retrieve a configuration option by key, using a default value if not present.
125125
@@ -235,7 +235,7 @@ cdef class Options:
235235
return <bytes>PyBytes_FromStringAndSize(<const char*>&vec[0], vec.size())
236236

237237
@staticmethod
238-
def deserialize(bytes serialized_buffer):
238+
def deserialize(bytes serialized_buffer not None):
239239
"""
240240
Deserialize a binary buffer into an Options object.
241241

0 commit comments

Comments
 (0)