Skip to content

Commit e465c8a

Browse files
asmirnov69ericmjl
andauthored
Apply suggestions from code review
@ericmjl improvements of method_call_ctx_factory description Co-authored-by: Eric Ma <[email protected]>
1 parent 6b5d03e commit e465c8a

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

pandas_flavor/register.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,45 @@
99
method_call_ctx_factory = None
1010

1111

12-
def handle_pandas_extention_call(method, method_signature, obj, args, kwargs):
12+
def handle_pandas_extension_call(method, method_signature, obj, args, kwargs):
1313
"""
14-
This function is called when the user calls the registered method on pandas dataframe object.
15-
pandas extention mechanism passes args and kwargs of original method call as it was applied to obj
14+
This function is called when the user calls a pandas DataFrame object's method.
15+
The pandas extension mechanism passes args and kwargs of original method call as it is applied to obj
1616
17-
Implementation uses global var *method_call_ctx_factory"
17+
Our implementation uses the global variable `method_call_ctx_factory`.
1818
19-
a) case when *method_call_ctx_factory* is None
20-
In this case the implementation calls the registered method with unmodified args and kwargs and returns underlying method result.
19+
`method_call_ctx_factory` can be either None or an abstract class.
2120
22-
b) case when *method_call_ctx_factory* is not None
23-
In this case *method_call_ctx_factory* expected to refer to the function to create the context object. The context object will be used
24-
to process inputs and outputs of *method* call. It is also possible that the context object method *handle_start_method_call*
25-
will modify original args and kwargs before *method* call.
21+
When `method_call_ctx_factory` is None, the implementation calls the registered method with unmodified args and kwargs and returns underlying method result.
22+
23+
When `method_call_ctx_factory` is not None, `method_call_ctx_factory` is expected to refer to the function to create the context object.
24+
The context object will be used to process inputs and outputs of `method` calls.
25+
It is also possible that the context object method `handle_start_method_call`
26+
will modify original args and kwargs before `method` call.
27+
28+
`method_call_ctx_factory` is a function that should have the following signature:
29+
30+
`f(method_name: str, args: list, kwargs: dict) -> MethodCallCtx`
2631
27-
method_call_ctx_factory function signature: (method_name: str, args: list, kwargs: dict) -> MethodCallCtx
2832
2933
MethodCallCtx is an abstract class:
3034
class MethodCallCtx(abc.ABC):
35+
3136
@abstractmethod
32-
def __enter__(self) -> None: raise NotImplemented
37+
def __enter__(self) -> None:
38+
raise NotImplemented
39+
3340
@abstractmethod
34-
def __exit__(self, exc_type, exc_value, traceback) -> None: raise NotImplemented
41+
def __exit__(self, exc_type, exc_value, traceback) -> None:
42+
raise NotImplemented
43+
3544
@abstractmethod
36-
def handle_start_method_call(self, method_name: str, method_signature: inspect.Signature, method_args: list, method_kwargs: dict) -> tuple(list, dict): raise NotImplemented
45+
def handle_start_method_call(self, method_name: str, method_signature: inspect.Signature, method_args: list, method_kwargs: dict) -> tuple(list, dict):
46+
raise NotImplemented
47+
3748
@abstractmethod
38-
def handle_end_method_call(self, ret: object) -> None: raise NotImplemented
49+
def handle_end_method_call(self, ret: object) -> None:
50+
raise NotImplemented
3951
4052
4153
Parameters

0 commit comments

Comments
 (0)