You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As it stands right now, the public interface for this library is pymkts.Client. However, all it actually does is proxy calls to either JsonRpcClient or GRPCClient. Which is fine, except for the fact that the return values of the two underlying clients are not always compatible. This breaks the principle of composability. For example:
Client(grpc=False).write() returns {'responses': None} on success and {'responses': [{'error': 'message', 'version': 'v'}] on error.
Meanwhile, Client(grpc=True).write() returns protobuf descriptors (essentially, attribute-access-only dicts).
Therefore, writing code against pymkts.Client will break if you switch between the real underlying clients. IMO that's no good. Currently the only "troublesome" methods are Client.write and Client.destroy, but, it will only get worse as the API grows.
I see four options:
Convert responses from the GRPCClient to be dictionaries compatible with those returned from JsonRpcClient (maintains backwards compatibility, simple but no useful type-hinting or code-completion)
Convert responses from both clients to be attribute-accessable dictionaries[1] (maintains backwards compatibility for both clients, simple but no useful type-hinting or code-completion)
Add basic response data classes[2] and convert the responses from both clients to them. Somewhat less simple, but provides useful type-hinting and code-completion, and done correctly, could maintain backwards compatibilty with both GRPCClient and JsonRpcClient.
Do away with pymkts.Client all together and leave it up to users to pick between from pymarketstore import GRPCClient as Client or from pymarketstore import JsonRpcClient as Client.
Thoughts? I'm happy to refactor the code if it will get merged :)
# [1] attribute-accessible dictionariesclassAttrDict(dict):
def__getattr__(self, key):
returnself[key]
def__setattr__(self, key, value):
self[key] =value# [2] response data classes (written against the msgpack response format, but you get the idea)classWriteResponse:
def__init__(response):
self.responses=response['responses']
@propertydefsuccess(self) ->bool:
returnnotself.responses@propertydeferrors(self) ->List[AttrDict]:
return [AttrDict(r) forrinself.responses] # or even better, a list of ErrorResponse instances
The text was updated successfully, but these errors were encountered:
As it stands right now, the public interface for this library is
pymkts.Client
. However, all it actually does is proxy calls to eitherJsonRpcClient
orGRPCClient
. Which is fine, except for the fact that the return values of the two underlying clients are not always compatible. This breaks the principle of composability. For example:Client(grpc=False).write()
returns{'responses': None}
on success and{'responses': [{'error': 'message', 'version': 'v'}]
on error.Meanwhile,
Client(grpc=True).write()
returns protobuf descriptors (essentially, attribute-access-only dicts).Therefore, writing code against
pymkts.Client
will break if you switch between the real underlying clients. IMO that's no good. Currently the only "troublesome" methods areClient.write
andClient.destroy
, but, it will only get worse as the API grows.I see four options:
GRPCClient
to be dictionaries compatible with those returned fromJsonRpcClient
(maintains backwards compatibility, simple but no useful type-hinting or code-completion)GRPCClient
andJsonRpcClient
.pymkts.Client
all together and leave it up to users to pick betweenfrom pymarketstore import GRPCClient as Client
orfrom pymarketstore import JsonRpcClient as Client
.Thoughts? I'm happy to refactor the code if it will get merged :)
The text was updated successfully, but these errors were encountered: