Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit d214d64

Browse files
authored
fix: support docstrings without type added (#311)
* fix: support docstrings without type info * test: update goldens * fix: update spacing * test: update goldens * fix: update prefix start/end removal * test: update goldens * fix: apply updates * fix: update comments * fix: update docstring and refactor recurring variable
1 parent 220951d commit d214d64

10 files changed

Lines changed: 186 additions & 25 deletions

docfx_yaml/extension.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,15 @@ def _update_friendly_package_name(path):
845845
# Find the index of the current default value argument
846846
index = len(args) + count - offset_count
847847

848-
# Only add defaultValue when str(default) doesn't contain object address string(object at 0x)
849-
# inspect.getargspec method will return wrong defaults which contain object address for some default values, like sys.stdout
850-
if 'object at 0x' not in str(default):
851-
args[index]['defaultValue'] = str(default)
848+
# Only add defaultValue when str(default) doesn't
849+
# contain object address string, for example:
850+
# (object at 0x) or <lambda> at 0x7fed4d57b5e0,
851+
# otherwise inspect.getargspec method will return wrong
852+
# defaults which contain object address for some,
853+
# like sys.stdout.
854+
default_string = str(default)
855+
if 'at 0x' not in default_string:
856+
args[index]['defaultValue'] = default_string
852857
# If we cannot find the argument, it is missing a type and was taken out intentionally.
853858
except IndexError:
854859
pass
@@ -973,12 +978,23 @@ def _update_friendly_package_name(path):
973978
if arg['id'] in variables:
974979
# Retrieve argument info from extracted map of variable info
975980
arg_var = variables[arg['id']]
976-
arg['var_type'] = arg_var.get('var_type')
977981
arg['description'] = arg_var.get('description')
978982

979-
# Only add arguments with type and description.
980-
if not (arg.get('var_type') and arg.get('description')):
983+
# Ignore the entry if we're missing the description.
984+
if not arg.get('description'):
981985
incomplete_args.append(arg)
986+
continue
987+
988+
if (arg_var_type := arg_var.get('var_type')):
989+
arg['var_type'] = arg_var_type
990+
continue
991+
992+
# If the type is not documented or missing from type_hint,
993+
# ignore the entry.
994+
if not arg.get('var_type'):
995+
incomplete_args.append(arg)
996+
continue
997+
982998

983999
# Remove any arguments with missing type or description from the YAML.
9841000
for incomplete_arg in incomplete_args:

tests/testdata/goldens/gapic-auto/google.cloud.texttospeech_v1.services.text_to_speech.TextToSpeechAsyncClient.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,12 @@ items:
349349
syntax:
350350
content: "get_transport_class() -> typing.Type[\n google.cloud.texttospeech_v1.services.text_to_speech.transports.base.TextToSpeechTransport\n\
351351
]"
352-
parameters: []
352+
parameters:
353+
- defaultValue: None
354+
description: The name of the desired transport. If none is provided, then the
355+
first transport in the registry is used.
356+
id: label
357+
var_type: str
353358
type: method
354359
uid: google.cloud.texttospeech_v1.services.text_to_speech.TextToSpeechAsyncClient.get_transport_class
355360
- attributes: []

tests/testdata/goldens/gapic-auto/google.cloud.texttospeech_v1beta1.services.text_to_speech.TextToSpeechAsyncClient.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,12 @@ items:
349349
syntax:
350350
content: "get_transport_class() -> typing.Type[\n google.cloud.texttospeech_v1beta1.services.text_to_speech.transports.base.TextToSpeechTransport\n\
351351
]"
352-
parameters: []
352+
parameters:
353+
- defaultValue: None
354+
description: The name of the desired transport. If none is provided, then the
355+
first transport in the registry is used.
356+
id: label
357+
var_type: str
353358
type: method
354359
uid: google.cloud.texttospeech_v1beta1.services.text_to_speech.TextToSpeechAsyncClient.get_transport_class
355360
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.publisher.client.Client.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ items:
6868
\ typing.Sequence\n ] = (),\n publisher_options: typing.Union[\n \
6969
\ google.cloud.pubsub_v1.types.PublisherOptions, typing.Sequence\n ] =\
7070
\ (),\n **kwargs: typing.Any\n)"
71-
parameters: []
71+
parameters:
72+
- description: The settings for batch publishing.
73+
id: batch_settings
74+
var_type: typing.Union[<xref uid="google.cloud.pubsub_v1.types.BatchSettings">google.cloud.pubsub_v1.types.BatchSettings</xref>,
75+
typing.Sequence]
76+
- defaultValue: ()
77+
description: The options for the publisher client. Note that enabling message
78+
ordering will override the publish retry timeout to be infinite.
79+
id: publisher_options
80+
var_type: typing.Union[<xref uid="google.cloud.pubsub_v1.types.PublisherOptions">google.cloud.pubsub_v1.types.PublisherOptions</xref>,
81+
typing.Sequence]
7282
type: class
7383
uid: google.cloud.pubsub_v1.publisher.client.Client
7484
- attributes: []
@@ -480,7 +490,14 @@ items:
480490
content: "from_service_account_file(\n filename: str,\n batch_settings:\
481491
\ typing.Union[\n google.cloud.pubsub_v1.types.BatchSettings, typing.Sequence\n\
482492
\ ] = (),\n **kwargs: typing.Any\n) -> google.cloud.pubsub_v1.publisher.client.Client"
483-
parameters: []
493+
parameters:
494+
- description: The path to the service account private key JSON file.
495+
id: filename
496+
var_type: str
497+
- description: The settings for batch publishing.
498+
id: batch_settings
499+
var_type: typing.Union[<xref uid="google.cloud.pubsub_v1.types.BatchSettings">google.cloud.pubsub_v1.types.BatchSettings</xref>,
500+
typing.Sequence]
484501
type: method
485502
uid: google.cloud.pubsub_v1.publisher.client.Client.from_service_account_file
486503
- attributes: []
@@ -527,7 +544,14 @@ items:
527544
content: "from_service_account_json(\n filename: str,\n batch_settings:\
528545
\ typing.Union[\n google.cloud.pubsub_v1.types.BatchSettings, typing.Sequence\n\
529546
\ ] = (),\n **kwargs: typing.Any\n) -> google.cloud.pubsub_v1.publisher.client.Client"
530-
parameters: []
547+
parameters:
548+
- description: The path to the service account private key JSON file.
549+
id: filename
550+
var_type: str
551+
- description: The settings for batch publishing.
552+
id: batch_settings
553+
var_type: typing.Union[<xref uid="google.cloud.pubsub_v1.types.BatchSettings">google.cloud.pubsub_v1.types.BatchSettings</xref>,
554+
typing.Sequence]
531555
type: method
532556
uid: google.cloud.pubsub_v1.publisher.client.Client.from_service_account_json
533557
- attributes: []
@@ -1087,7 +1111,20 @@ items:
10871111
- description: If publishing the <code>message</code> would exceed the max size
10881112
limit on the backend.
10891113
var_type: pubsub_v1.publisher.exceptions.MessageTooLargeError
1090-
parameters: []
1114+
parameters:
1115+
- description: The topic to publish messages to.
1116+
id: topic
1117+
var_type: str
1118+
- defaultValue: ''
1119+
description: A bytestring representing the message body. This must be a bytestring.
1120+
id: data
1121+
var_type: bytes
1122+
- defaultValue: _MethodDefault._DEFAULT_VALUE
1123+
description: A string that identifies related messages for which publish order
1124+
should be respected. Message ordering must be enabled for this client to use
1125+
this feature.
1126+
id: ordering_key
1127+
var_type: str
10911128
type: method
10921129
uid: google.cloud.pubsub_v1.publisher.client.Client.publish
10931130
- attributes: []
@@ -1113,7 +1150,14 @@ items:
11131150
- description: If the topic/ordering key combination has not been seen before
11141151
by this client.
11151152
var_type: ValueError
1116-
parameters: []
1153+
parameters:
1154+
- description: The topic to publish messages to.
1155+
id: topic
1156+
var_type: str
1157+
- description: A string that identifies related messages for which publish order
1158+
should be respected.
1159+
id: ordering_key
1160+
var_type: str
11171161
type: method
11181162
uid: google.cloud.pubsub_v1.publisher.client.Client.resume_publish
11191163
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.publisher.futures.Future.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ items:
7777
syntax:
7878
content: "add_done_callback(\n callback: typing.Callable[[pubsub_v1.publisher.futures.Future],\
7979
\ typing.Any]\n) -> None"
80-
parameters: []
80+
parameters:
81+
- description: A callable that will be called with this future as its only argument
82+
when the future completes or is cancelled. The callable will always be called
83+
by a thread in the same process in which it was added. If the future has already
84+
completed or been cancelled then the callable will be called immediately.
85+
These callables are called in the order that they were added.
86+
id: callback
87+
var_type: typing.Callable[[pubsub_v1.publisher.futures.Future], typing.Any]
8188
type: method
8289
uid: google.cloud.pubsub_v1.publisher.futures.Future.add_done_callback
8390
- attributes: []
@@ -197,7 +204,11 @@ items:
197204
var_type: concurrent.futures.TimeoutError
198205
- description: For undefined exceptions in the underlying call execution.
199206
var_type: Exception
200-
parameters: []
207+
parameters:
208+
- defaultValue: None
209+
description: The number of seconds before this call times out and raises TimeoutError.
210+
id: timeout
211+
var_type: typing.Union[int, float]
201212
type: method
202213
uid: google.cloud.pubsub_v1.publisher.futures.Future.result
203214
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.subscriber.client.Client.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,10 @@ items:
673673
syntax:
674674
content: "from_service_account_file(\n filename: str, **kwargs: typing.Any\n\
675675
) -> google.cloud.pubsub_v1.subscriber.client.Client"
676-
parameters: []
676+
parameters:
677+
- description: The path to the service account private key json file.
678+
id: filename
679+
var_type: str
677680
type: method
678681
uid: google.cloud.pubsub_v1.subscriber.client.Client.from_service_account_file
679682
- attributes: []
@@ -719,7 +722,10 @@ items:
719722
syntax:
720723
content: "from_service_account_json(\n filename: str, **kwargs: typing.Any\n\
721724
) -> google.cloud.pubsub_v1.subscriber.client.Client"
722-
parameters: []
725+
parameters:
726+
- description: The path to the service account private key json file.
727+
id: filename
728+
var_type: str
723729
type: method
724730
uid: google.cloud.pubsub_v1.subscriber.client.Client.from_service_account_json
725731
- attributes: []
@@ -1692,13 +1698,45 @@ items:
16921698
\ = None,\n use_legacy_flow_control: bool = False,\n await_callbacks_on_shutdown:\
16931699
\ bool = False,\n) -> google.cloud.pubsub_v1.subscriber.futures.StreamingPullFuture"
16941700
parameters:
1701+
- description: The name of the subscription. The subscription should have already
1702+
been created (for example, by using <code>create_subscription</code>).
1703+
id: subscription
1704+
var_type: str
1705+
- description: The callback function. This function receives the message as its
1706+
only argument and will be called from a different thread/ process depending
1707+
on the scheduling strategy.
1708+
id: callback
1709+
var_type: typing.Callable[[subscriber.message.Message], typing.Any]
1710+
- defaultValue: ()
1711+
description: The flow control settings. Use this to prevent situations where
1712+
you are inundated with too many messages at once.
1713+
id: flow_control
1714+
var_type: typing.Union[<xref uid="google.cloud.pubsub_v1.types.FlowControl">google.cloud.pubsub_v1.types.FlowControl</xref>,
1715+
typing.Sequence]
1716+
- defaultValue: None
1717+
description: An optional *scheduler* to use when executing the callback. This
1718+
controls how callbacks are executed concurrently. This object must not be
1719+
shared across multiple <code>SubscriberClient</code> instances.
1720+
id: scheduler
1721+
var_type: typing.Optional[subscriber.scheduler.ThreadScheduler]
16951722
- defaultValue: 'False'
16961723
description: If set to <code>True</code>, flow control at the Cloud Pub/Sub
16971724
server is disabled, though client-side flow control is still enabled. If set
16981725
to <code>False</code> (default), both server-side and client-side flow control
16991726
are enabled.
17001727
id: use_legacy_flow_control
17011728
var_type: bool
1729+
- defaultValue: 'False'
1730+
description: If <code>True</code>, after canceling the returned future, the
1731+
latter's <code>result()</code> method will block until the background stream
1732+
and its helper threads have been terminated, and all currently executing message
1733+
callbacks are done processing. If <code>False</code> (default), the returned
1734+
future's <code>result()</code> method will not block after canceling the future.
1735+
The method will instead return immediately after the background stream and
1736+
its helper threads have been terminated, but some of the message callback
1737+
threads might still be running at that point.
1738+
id: await_callbacks_on_shutdown
1739+
var_type: bool
17021740
type: method
17031741
uid: google.cloud.pubsub_v1.subscriber.client.Client.subscribe
17041742
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.subscriber.futures.Future.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ items:
194194
var_type: concurrent.futures.TimeoutError
195195
- description: If the operation did not succeed for another reason.
196196
var_type: AcknowledgeError
197-
parameters: []
197+
parameters:
198+
- defaultValue: None
199+
description: The number of seconds before this call times out and raises TimeoutError.
200+
id: timeout
201+
var_type: typing.Union[int, float]
198202
type: method
199203
uid: google.cloud.pubsub_v1.subscriber.futures.Future.result
200204
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.subscriber.message.Message.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@ items:
6969
content: 'Message(message: types.PubsubMessage._meta._pb, ack_id: str, delivery_attempt:
7070
int, request_queue: queue.Queue, exactly_once_delivery_enabled_func: typing.Callable[[],
7171
bool] = <function Message.<lambda>>)'
72-
parameters: []
72+
parameters:
73+
- description: The ack_id received from Pub/Sub.
74+
id: ack_id
75+
var_type: str
76+
- description: The delivery attempt counter received from Pub/Sub if a DeadLetterPolicy
77+
is set on the subscription, and zero otherwise.
78+
id: delivery_attempt
79+
var_type: int
80+
- description: A Callable that returns whether exactly-once delivery is currently-enabled.
81+
Defaults to a lambda that always returns False.
82+
id: exactly_once_delivery_enabled_func
83+
var_type: typing.Callable[[], bool]
7384
type: method
7485
uid: google.cloud.pubsub_v1.subscriber.message.Message
7586
- attributes: []
@@ -369,7 +380,12 @@ items:
369380
'
370381
syntax:
371382
content: 'modify_ack_deadline(seconds: int) -> None'
372-
parameters: []
383+
parameters:
384+
- description: The number of seconds to set the lease deadline to. This should
385+
be between 0 and 600. Due to network latency, values below 10 are advised
386+
against.
387+
id: seconds
388+
var_type: int
373389
type: method
374390
uid: google.cloud.pubsub_v1.subscriber.message.Message.modify_ack_deadline
375391
- attributes: []
@@ -435,7 +451,12 @@ items:
435451
'
436452
syntax:
437453
content: "modify_ack_deadline_with_response(\n seconds: int,\n) -> google.cloud.pubsub_v1.subscriber.futures.Future"
438-
parameters: []
454+
parameters:
455+
- description: The number of seconds to set the lease deadline to. This should
456+
be between 0 and 600. Due to network latency, values below 10 are advised
457+
against.
458+
id: seconds
459+
var_type: int
439460
type: method
440461
uid: google.cloud.pubsub_v1.subscriber.message.Message.modify_ack_deadline_with_response
441462
- attributes: []

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.subscriber.scheduler.Scheduler.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ items:
8787
'
8888
syntax:
8989
content: "shutdown(\n await_msg_callbacks: bool = False,\n) -> typing.List[pubsub_v1.subscriber.message.Message]"
90-
parameters: []
90+
parameters:
91+
- defaultValue: 'False'
92+
description: If <code>True</code>, the method will block until all currently
93+
executing callbacks are done processing. If <code>False</code> (default),
94+
the method will not wait for the currently running callbacks to complete.
95+
id: await_msg_callbacks
96+
var_type: bool
9197
type: method
9298
uid: google.cloud.pubsub_v1.subscriber.scheduler.Scheduler.shutdown
9399
references:

tests/testdata/goldens/gapic-combo/google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ items:
2121
syntax:
2222
content: "ThreadScheduler(\n executor: typing.Optional[concurrent.futures.thread.ThreadPoolExecutor]\
2323
\ = None,\n)"
24-
parameters: []
24+
parameters:
25+
- defaultValue: None
26+
description: An optional executor to use. If not specified, a default one will
27+
be created.
28+
id: executor
29+
var_type: typing.Optional[concurrent.futures.thread.ThreadPoolExecutor]
2530
type: class
2631
uid: google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler
2732
- &id001
@@ -81,7 +86,13 @@ items:
8186
'
8287
syntax:
8388
content: "shutdown(\n await_msg_callbacks: bool = False,\n) -> typing.List[pubsub_v1.subscriber.message.Message]"
84-
parameters: []
89+
parameters:
90+
- defaultValue: 'False'
91+
description: If <code>True</code>, the method will block until all currently
92+
executing executor threads are done processing. If <code>False</code> (default),
93+
the method will not wait for the currently running threads to complete.
94+
id: await_msg_callbacks
95+
var_type: bool
8596
type: method
8697
uid: google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler.shutdown
8798
references:

0 commit comments

Comments
 (0)