Skip to content

Commit

Permalink
Generate service functions on the thrift python client class
Browse files Browse the repository at this point in the history
Summary:
The concept of async and sync clients is new to thrift python, in thrift py3 every client was async, and the client methods were located directly on the class. This leads to potential issues when enabling auto-migrate as these methods are no longer there. Just sticking references to the Async class methods directly on the class itself to avoid this problem.

This does require a bit of a hack in that we have to tell pyre to ignore the fact that we have no annotation. I'm not 100% sure this is correct, but I was looking into adding the correct annotation and what pyre expects here is something like: `typing.Callable(Async.getMetadaField)[[Named(self, Async), Named(key, str), KeywordOnly(rpc_options, Optional[RpcOptions], default)], Coroutine[typing.Any, typing.Any, str]]`, and this just seems like way too much duplication to me. Optimally I'd like tell pyre to just use the inferred type but I don't think there's any to do that.

Reviewed By: ahilger

Differential Revision: D67056477

fbshipit-source-id: 06aa228b911a24f087cbff56803934356d5d1a94
  • Loading branch information
Filip Francetic authored and facebook-github-bot committed Dec 12, 2024
1 parent 94a937a commit 10edf95
Show file tree
Hide file tree
Showing 41 changed files with 916 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ class Async({{#service:extends}}{{!
) -> {{service:parent_service_name}}_{{service:name}}.Async:
return self.create{{service:name}}()
{{/service:interactions}}

{{#service:supported_functions}}
# pyre-ignore[4]: Missing annotation.{{! Adding an annotation here would require way too much duplication }}
{{function:name}} = Async.{{function:name}}
{{/service:supported_functions}}

class Sync({{#service:extends}}{{!
}}{{> services/client_module_path}}.Sync{{!
}}{{/service:extends}}{{^service:extends?}}{{!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ async def adapted_param(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
adapted_return = Async.adapted_return
# pyre-ignore[4]: Missing annotation.
adapted_param = Async.adapted_param

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async def simple_rpc(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -152,6 +156,10 @@ async def simple_rpc(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -414,6 +422,28 @@ async def rpc_skipped_codegen(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
ping = Async.ping
# pyre-ignore[4]: Missing annotation.
getRandomData = Async.getRandomData
# pyre-ignore[4]: Missing annotation.
sink = Async.sink
# pyre-ignore[4]: Missing annotation.
putDataById = Async.putDataById
# pyre-ignore[4]: Missing annotation.
hasDataById = Async.hasDataById
# pyre-ignore[4]: Missing annotation.
getDataById = Async.getDataById
# pyre-ignore[4]: Missing annotation.
deleteDataById = Async.deleteDataById
# pyre-ignore[4]: Missing annotation.
lobDataById = Async.lobDataById
# pyre-ignore[4]: Missing annotation.
invalid_return_for_hack = Async.invalid_return_for_hack
# pyre-ignore[4]: Missing annotation.
rpc_skipped_codegen = Async.rpc_skipped_codegen

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -691,6 +721,12 @@ async def getDataByKey1(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
getDataByKey0 = Async.getDataByKey0
# pyre-ignore[4]: Missing annotation.
getDataByKey1 = Async.getDataByKey1

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async def simple_rpc(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -152,6 +156,10 @@ async def simple_rpc(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -414,6 +422,28 @@ async def rpc_skipped_codegen(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
ping = Async.ping
# pyre-ignore[4]: Missing annotation.
getRandomData = Async.getRandomData
# pyre-ignore[4]: Missing annotation.
sink = Async.sink
# pyre-ignore[4]: Missing annotation.
putDataById = Async.putDataById
# pyre-ignore[4]: Missing annotation.
hasDataById = Async.hasDataById
# pyre-ignore[4]: Missing annotation.
getDataById = Async.getDataById
# pyre-ignore[4]: Missing annotation.
deleteDataById = Async.deleteDataById
# pyre-ignore[4]: Missing annotation.
lobDataById = Async.lobDataById
# pyre-ignore[4]: Missing annotation.
invalid_return_for_hack = Async.invalid_return_for_hack
# pyre-ignore[4]: Missing annotation.
rpc_skipped_codegen = Async.rpc_skipped_codegen

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -691,6 +721,12 @@ async def getDataByKey1(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
getDataByKey0 = Async.getDataByKey0
# pyre-ignore[4]: Missing annotation.
getDataByKey1 = Async.getDataByKey1

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ async def simple_rpc(
is_mutable_types=True,
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -158,6 +162,10 @@ async def simple_rpc(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -431,6 +439,28 @@ async def rpc_skipped_codegen(
is_mutable_types=True,
)


# pyre-ignore[4]: Missing annotation.
ping = Async.ping
# pyre-ignore[4]: Missing annotation.
getRandomData = Async.getRandomData
# pyre-ignore[4]: Missing annotation.
sink = Async.sink
# pyre-ignore[4]: Missing annotation.
putDataById = Async.putDataById
# pyre-ignore[4]: Missing annotation.
hasDataById = Async.hasDataById
# pyre-ignore[4]: Missing annotation.
getDataById = Async.getDataById
# pyre-ignore[4]: Missing annotation.
deleteDataById = Async.deleteDataById
# pyre-ignore[4]: Missing annotation.
lobDataById = Async.lobDataById
# pyre-ignore[4]: Missing annotation.
invalid_return_for_hack = Async.invalid_return_for_hack
# pyre-ignore[4]: Missing annotation.
rpc_skipped_codegen = Async.rpc_skipped_codegen

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -720,6 +750,12 @@ async def getDataByKey1(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
getDataByKey0 = Async.getDataByKey0
# pyre-ignore[4]: Missing annotation.
getDataByKey1 = Async.getDataByKey1

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ async def echo(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
echo = Async.echo

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ async def echo(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
echo = Async.echo

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ async def simple_rpc(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -152,6 +156,10 @@ async def simple_rpc(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -414,6 +422,28 @@ async def rpc_skipped_codegen(
rpc_options=rpc_options,
)


# pyre-ignore[4]: Missing annotation.
ping = Async.ping
# pyre-ignore[4]: Missing annotation.
getRandomData = Async.getRandomData
# pyre-ignore[4]: Missing annotation.
sink = Async.sink
# pyre-ignore[4]: Missing annotation.
putDataById = Async.putDataById
# pyre-ignore[4]: Missing annotation.
hasDataById = Async.hasDataById
# pyre-ignore[4]: Missing annotation.
getDataById = Async.getDataById
# pyre-ignore[4]: Missing annotation.
deleteDataById = Async.deleteDataById
# pyre-ignore[4]: Missing annotation.
lobDataById = Async.lobDataById
# pyre-ignore[4]: Missing annotation.
invalid_return_for_hack = Async.invalid_return_for_hack
# pyre-ignore[4]: Missing annotation.
rpc_skipped_codegen = Async.rpc_skipped_codegen

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -691,6 +721,12 @@ async def getDataByKey1(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
getDataByKey0 = Async.getDataByKey0
# pyre-ignore[4]: Missing annotation.
getDataByKey1 = Async.getDataByKey1

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ async def simple_rpc(
is_mutable_types=True,
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -158,6 +162,10 @@ async def simple_rpc(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
simple_rpc = Async.simple_rpc

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -431,6 +439,28 @@ async def rpc_skipped_codegen(
is_mutable_types=True,
)


# pyre-ignore[4]: Missing annotation.
ping = Async.ping
# pyre-ignore[4]: Missing annotation.
getRandomData = Async.getRandomData
# pyre-ignore[4]: Missing annotation.
sink = Async.sink
# pyre-ignore[4]: Missing annotation.
putDataById = Async.putDataById
# pyre-ignore[4]: Missing annotation.
hasDataById = Async.hasDataById
# pyre-ignore[4]: Missing annotation.
getDataById = Async.getDataById
# pyre-ignore[4]: Missing annotation.
deleteDataById = Async.deleteDataById
# pyre-ignore[4]: Missing annotation.
lobDataById = Async.lobDataById
# pyre-ignore[4]: Missing annotation.
invalid_return_for_hack = Async.invalid_return_for_hack
# pyre-ignore[4]: Missing annotation.
rpc_skipped_codegen = Async.rpc_skipped_codegen

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down Expand Up @@ -720,6 +750,12 @@ async def getDataByKey1(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
getDataByKey0 = Async.getDataByKey0
# pyre-ignore[4]: Missing annotation.
getDataByKey1 = Async.getDataByKey1

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ async def echo(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
echo = Async.echo

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ async def get500(
"Empty Response",
)


# pyre-ignore[4]: Missing annotation.
doBland = Async.doBland
# pyre-ignore[4]: Missing annotation.
doRaise = Async.doRaise
# pyre-ignore[4]: Missing annotation.
get200 = Async.get200
# pyre-ignore[4]: Missing annotation.
get500 = Async.get500

class Sync(_fbthrift_python_SyncClient):
@staticmethod
def __get_thrift_name__() -> str:
Expand Down
Loading

0 comments on commit 10edf95

Please sign in to comment.