googleapis / gapic-generator-python

Generate Python API client libraries from Protocol Buffers.
Apache License 2.0
122 stars 69 forks source link

Reduce code duplication in method signatures throughout the code base #2254

Open parthea opened 2 days ago

parthea commented 2 days ago

See the diff in PR https://github.com/googleapis/gapic-generator-python/pull/2253/files which shows changes to the following code which appears throughout the code base

        retry: OptionalRetry = gapic_v1.method.DEFAULT,
        timeout: Union[float, object] = gapic_v1.method.DEFAULT,
        metadata: Sequence[Tuple[str, str]] = (),
    )

We can reduce code duplication by using common code for a common method signature. As a pre-requisite, we need to fix the following issues

Address the inconsistency with the default values in timeout.

See here https://github.com/googleapis/gapic-generator-python/blob/515dc8ac17b9a8177feaa84416ab88e671c5359c/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/_client_macros.j2#L31-L32

and here https://github.com/googleapis/gapic-generator-python/blob/515dc8ac17b9a8177feaa84416ab88e671c5359c/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/transports/rest.py.j2#L205

Address the inconsistency in the type for Async REST and Async Mixins and pagers, where we have bothOptionalAsyncRetry and OptionalRetry defined as the type for retry

See here https://github.com/googleapis/gapic-generator-python/blob/515dc8ac17b9a8177feaa84416ab88e671c5359c/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/transports/rest_asyncio.py.j2#L62

and here https://github.com/googleapis/gapic-generator-python/blob/515dc8ac17b9a8177feaa84416ab88e671c5359c/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/_async_mixins.py.j2#L10

and here OptionalAsyncRetry https://github.com/googleapis/gapic-generator-python/blob/515dc8ac17b9a8177feaa84416ab88e671c5359c/gapic/templates/%25namespace/%25name_%25version/%25sub/services/%25service/pagers.py.j2#L16