Skip to content

Commit 98bc9a2

Browse files
authored
chore: better error messages + bump version (#172)
Signed-off-by: Avik Basu <[email protected]>
1 parent 225e8b0 commit 98bc9a2

File tree

7 files changed

+178
-159
lines changed

7 files changed

+178
-159
lines changed

poetry.lock

Lines changed: 141 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pynumaflow/reducer/async_server.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
from typing import Optional
23

34
import aiorun
45
import grpc
@@ -21,10 +22,12 @@
2122
Reducer,
2223
)
2324

24-
from pynumaflow.shared.server import NumaflowServer, checkInstance, start_async_server
25+
from pynumaflow.shared.server import NumaflowServer, check_instance, start_async_server
2526

2627

27-
def get_handler(reducer_handler: ReduceCallable, init_args: tuple = (), init_kwargs: dict = None):
28+
def get_handler(
29+
reducer_handler: ReduceCallable, init_args: tuple = (), init_kwargs: Optional[dict] = None
30+
):
2831
"""
2932
Get the correct handler type based on the arguments passed
3033
"""
@@ -35,13 +38,16 @@ def get_handler(reducer_handler: ReduceCallable, init_args: tuple = (), init_kwa
3538
raise TypeError("Cannot pass function handler with init args or kwargs")
3639
# return the function handler
3740
return reducer_handler
38-
elif not checkInstance(reducer_handler, Reducer) and issubclass(reducer_handler, Reducer):
41+
elif not check_instance(reducer_handler, Reducer) and issubclass(reducer_handler, Reducer):
3942
# if handler is type of Class Reducer, create a new instance of
4043
# a ReducerBuilderClass
4144
return _ReduceBuilderClass(reducer_handler, init_args, init_kwargs)
4245
else:
43-
_LOGGER.error("Invalid Type: please provide the handler or the class name")
44-
raise TypeError("Inavlid Type: please provide the handler or the class name")
46+
_LOGGER.error(
47+
_error_msg := f"Invalid Class Type {reducer_handler}: "
48+
f"Please make sure the class type is passed, and it is a subclass of Reducer"
49+
)
50+
raise TypeError(_error_msg)
4551

4652

4753
class ReduceAsyncServer(NumaflowServer):

pynumaflow/reducestreamer/async_server.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ReduceStreamer,
2323
)
2424

25-
from pynumaflow.shared.server import NumaflowServer, checkInstance, start_async_server
25+
from pynumaflow.shared.server import NumaflowServer, check_instance, start_async_server
2626

2727

2828
def get_handler(
@@ -38,15 +38,18 @@ def get_handler(
3838
raise TypeError("Cannot pass function handler with init args or kwargs")
3939
# return the function handler
4040
return reducer_handler
41-
elif not checkInstance(reducer_handler, ReduceStreamer) and issubclass(
41+
elif not check_instance(reducer_handler, ReduceStreamer) and issubclass(
4242
reducer_handler, ReduceStreamer
4343
):
4444
# if handler is type of Class ReduceStreamer, create a new instance of
4545
# a ReducerBuilderClass
4646
return _ReduceStreamBuilderClass(reducer_handler, init_args, init_kwargs)
4747
else:
48-
_LOGGER.error("Invalid Type: please provide the handler or the class name")
49-
raise TypeError("Invalid Type: please provide the handler or the class name")
48+
_LOGGER.error(
49+
_error_msg := f"Invalid Class Type {reducer_handler}: "
50+
f"Please make sure the class type is passed, and it is a subclass of ReduceStreamer"
51+
)
52+
raise TypeError(_error_msg)
5053

5154

5255
class ReduceStreamAsyncServer(NumaflowServer):

pynumaflow/shared/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _reserve_port(port_num: int) -> Iterator[int]:
245245
sock.close()
246246

247247

248-
def checkInstance(instance, callable_type) -> bool:
248+
def check_instance(instance, callable_type) -> bool:
249249
"""
250250
Check if the given instance is of the given callable_type.
251251
"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pynumaflow"
3-
version = "0.7.1"
3+
version = "0.7.2"
44
description = "Provides the interfaces of writing Python User Defined Functions and Sinks for NumaFlow."
55
authors = ["NumaFlow Developers"]
66
readme = "README.md"

tests/reduce/test_async_reduce.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from google.protobuf import empty_pb2 as _empty_pb2
99
from grpc.aio._server import Server
1010

11-
from pynumaflow import setup_logging
1211
from pynumaflow._constants import WIN_START_TIME, WIN_END_TIME
12+
from pynumaflow.proto.reducer import reduce_pb2, reduce_pb2_grpc
1313
from pynumaflow.reducer import (
1414
Messages,
1515
Message,
@@ -18,15 +18,15 @@
1818
ReduceAsyncServer,
1919
Reducer,
2020
)
21-
from pynumaflow.proto.reducer import reduce_pb2, reduce_pb2_grpc
2221
from tests.testing_utils import (
2322
mock_message,
2423
mock_interval_window_start,
2524
mock_interval_window_end,
2625
get_time_args,
2726
)
2827

29-
LOGGER = setup_logging(__name__)
28+
logging.basicConfig(level=logging.DEBUG)
29+
LOGGER = logging.getLogger(__name__)
3030

3131

3232
def request_generator(count, request, resetkey: bool = False):
@@ -243,6 +243,13 @@ def test_error_init(self):
243243
with self.assertRaises(TypeError):
244244
ReduceAsyncServer(ExampleClass(0))
245245

246+
# Check that an invalid class is passed
247+
class ExampleBadClass:
248+
pass
249+
250+
with self.assertRaises(TypeError):
251+
ReduceAsyncServer(reducer_handler=ExampleBadClass)
252+
246253

247254
if __name__ == "__main__":
248255
logging.basicConfig(level=logging.DEBUG)

tests/reducestreamer/test_async_reduce.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ def test_error_init(self):
274274
with self.assertRaises(TypeError):
275275
ReduceStreamAsyncServer(ExampleClass(0))
276276

277+
# Check that an invalid class is passed
278+
class ExampleBadClass:
279+
pass
280+
281+
with self.assertRaises(TypeError):
282+
ReduceStreamAsyncServer(reduce_stream_handler=ExampleBadClass)
283+
277284

278285
if __name__ == "__main__":
279286
logging.basicConfig(level=logging.DEBUG)

0 commit comments

Comments
 (0)