feat: Use factory mode to init the operator instance in Python binding
This could be better
class Operator:
@classmethod
def from_config(scheme: str, **kwargs)-> Operator: ...
@classmethod
def from_async_operator(operator: AsyncOperator) -> Operator: ...
class AsyncOperator:
@classmethod
def from_config(scheme: str, **kwargs)-> AsyncOperator: ...
@classmethod
def from_operator(operator: Operator) -> AsyncOperator: ...
We use the factory mode instead of __init__ completely
Originally posted by @Zheaoli in https://github.com/apache/incubator-opendal/pull/3514#discussion_r1386123571
I want to preserve the naming of from_config to make space for us to introduce RFC-3197: Config for bindings.
By the way, is the API style like from_xxx widely used in python?
By the way, is the API style like
from_xxxwidely used in python?
Nope, a normal way
https://github.com/mitmproxy/mitmproxy/blob/746537e0511e0316a144e05e7ba8cc6f6e44768b/mitmproxy/coretypes/serializable.py#L30-L37
https://github.com/mitmproxy/mitmproxy/blob/746537e0511e0316a144e05e7ba8cc6f6e44768b/mitmproxy/certs.py#L378-L406
Nope, a normal way
I don't understand this statement.
Nope, a normal way means it does be widely used?
Nope, a normal way
I don't understand this statement.
Nope, a normal way means it does be widely used?
Sorry for confusing
I mean, this is a normal style from_xxx in Python. Many project use this conversion in factory mode
https://github.com/search?q=%22def+from_%22+repo%3Atensorflow%2Ftensorflow&type=code&ref=advsearch
I mean, this is a normal style
from_xxxin Python.
Got it, thanks for sharing.
I mean, this is a normal style
from_xxxin Python.Got it, thanks for sharing.
BTW, from_xxx is good pattern which is suggested in PEP8 "Explicit is better than implicit"
Seems cool, would you like to propose an RFC for python binding about this change? We can place them inside bindings/python/docs/rfcs.
This is the first RFC for python binding!
Seems cool, would you like to propose an RFC for python binding about this change? We can place them inside
bindings/python/docs/rfcs.This is the first RFC for python binding!
Of course!
@Xuanwo BTW, would you mind me adding a new label "RFC needed` to represent an issue which okay but needs a RFC before submitting the code
@Xuanwo BTW, would you mind me adding a new label "RFC needed` to represent an issue which okay but needs a RFC before submitting the code
I don't think we need this.
I check the code, https://github.com/apache/opendal/pull/3514 added the instance method, not class method, and https://github.com/apache/incubator-opendal/pull/3197 is merged, so any other things need to be solved?