Skip to content

Commit c632dde

Browse files
committed
Improved Python docstrings for union types.
1 parent 1aef6d8 commit c632dde

File tree

8 files changed

+2062
-73
lines changed

8 files changed

+2062
-73
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
# built documents.
6060
#
6161
# The short X.Y version.
62-
version = '3.40'
62+
version = '3.41'
6363
# The full version, including alpha/beta/rc tags.
64-
release = '3.40'
64+
release = '3.41'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

dropbox/async.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class LaunchResultBase(object):
1414
type of the synchronous response. See :class:`LaunchEmptyResult` for an
1515
example.
1616
17+
This class acts as a tagged union. Only one of the ``is_*`` methods will
18+
return true. To get the associated value of a tag (if one exists), use the
19+
corresponding ``get_*`` method.
20+
1721
:ivar str async_job_id: This response indicates that the processing is
1822
asynchronous. The string is an id that can be used to obtain the status
1923
of the asynchronous job.
@@ -37,25 +41,48 @@ def __init__(self, tag, value=None):
3741

3842
@classmethod
3943
def async_job_id(cls, val):
44+
"""
45+
Create an instance of this class set to the ``async_job_id`` tag with value ``val``.
46+
47+
:param str val:
48+
:rtype: LaunchResultBase
49+
"""
4050
return cls('async_job_id', val)
4151

4252
def is_async_job_id(self):
53+
"""
54+
Check if the union tag is ``async_job_id``.
55+
56+
:rtype: bool
57+
"""
4358
return self._tag == 'async_job_id'
4459

4560
def get_async_job_id(self):
61+
"""
62+
This response indicates that the processing is asynchronous. The string
63+
is an id that can be used to obtain the status of the asynchronous job.
64+
65+
Only call this if :meth:`is_async_job_id` is true.
66+
67+
:rtype: str
68+
"""
4669
if not self.is_async_job_id():
4770
raise AttributeError("tag 'async_job_id' not set")
4871
return self._value
4972

5073
def __repr__(self):
51-
return 'LaunchResultBase(%r)' % self._tag
74+
return 'LaunchResultBase(%r, %r)' % (self._tag, self._value)
5275

5376
class LaunchEmptyResult(LaunchResultBase):
5477
"""
5578
Result returned by methods that may either launch an asynchronous job or
5679
complete synchronously. Upon synchronous completion of the job, no
5780
additional information is returned.
5881
82+
This class acts as a tagged union. Only one of the ``is_*`` methods will
83+
return true. To get the associated value of a tag (if one exists), use the
84+
corresponding ``get_*`` method.
85+
5986
:ivar complete: The job finished synchronously and successfully.
6087
"""
6188

@@ -77,10 +104,15 @@ def __init__(self, tag, value=None):
77104
self._value = value
78105

79106
def is_complete(self):
107+
"""
108+
Check if the union tag is ``complete``.
109+
110+
:rtype: bool
111+
"""
80112
return self._tag == 'complete'
81113

82114
def __repr__(self):
83-
return 'LaunchEmptyResult(%r)' % self._tag
115+
return 'LaunchEmptyResult(%r, %r)' % (self._tag, self._value)
84116

85117
class PollArg(object):
86118
"""
@@ -140,6 +172,10 @@ class PollResultBase(object):
140172
the information returned upon job completion. See :class:`PollEmptyResult`
141173
for an example.
142174
175+
This class acts as a tagged union. Only one of the ``is_*`` methods will
176+
return true. To get the associated value of a tag (if one exists), use the
177+
corresponding ``get_*`` method.
178+
143179
:ivar in_progress: The asynchronous job is still in progress.
144180
"""
145181

@@ -162,16 +198,25 @@ def __init__(self, tag, value=None):
162198
self._value = value
163199

164200
def is_in_progress(self):
201+
"""
202+
Check if the union tag is ``in_progress``.
203+
204+
:rtype: bool
205+
"""
165206
return self._tag == 'in_progress'
166207

167208
def __repr__(self):
168-
return 'PollResultBase(%r)' % self._tag
209+
return 'PollResultBase(%r, %r)' % (self._tag, self._value)
169210

170211
class PollEmptyResult(PollResultBase):
171212
"""
172213
Result returned by methods that poll for the status of an asynchronous job.
173214
Upon completion of the job, no additional information is returned.
174215
216+
This class acts as a tagged union. Only one of the ``is_*`` methods will
217+
return true. To get the associated value of a tag (if one exists), use the
218+
corresponding ``get_*`` method.
219+
175220
:ivar complete: The asynchronous job has completed successfully.
176221
"""
177222

@@ -193,15 +238,24 @@ def __init__(self, tag, value=None):
193238
self._value = value
194239

195240
def is_complete(self):
241+
"""
242+
Check if the union tag is ``complete``.
243+
244+
:rtype: bool
245+
"""
196246
return self._tag == 'complete'
197247

198248
def __repr__(self):
199-
return 'PollEmptyResult(%r)' % self._tag
249+
return 'PollEmptyResult(%r, %r)' % (self._tag, self._value)
200250

201251
class PollError(object):
202252
"""
203253
Error returned by methods for polling the status of asynchronous job.
204254
255+
This class acts as a tagged union. Only one of the ``is_*`` methods will
256+
return true. To get the associated value of a tag (if one exists), use the
257+
corresponding ``get_*`` method.
258+
205259
:ivar invalid_async_job_id: The job ID is invalid.
206260
:ivar internal_error: Something went wrong with the job on Dropbox's end.
207261
You'll need to verify that the action you were taking succeeded, and if
@@ -232,16 +286,31 @@ def __init__(self, tag, value=None):
232286
self._value = value
233287

234288
def is_invalid_async_job_id(self):
289+
"""
290+
Check if the union tag is ``invalid_async_job_id``.
291+
292+
:rtype: bool
293+
"""
235294
return self._tag == 'invalid_async_job_id'
236295

237296
def is_internal_error(self):
297+
"""
298+
Check if the union tag is ``internal_error``.
299+
300+
:rtype: bool
301+
"""
238302
return self._tag == 'internal_error'
239303

240304
def is_other(self):
305+
"""
306+
Check if the union tag is ``other``.
307+
308+
:rtype: bool
309+
"""
241310
return self._tag == 'other'
242311

243312
def __repr__(self):
244-
return 'PollError(%r)' % self._tag
313+
return 'PollError(%r, %r)' % (self._tag, self._value)
245314

246315
LaunchResultBase._async_job_id_validator = bv.String(min_length=1)
247316
LaunchResultBase._tagmap = {

dropbox/dropbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
]
44

55
# TODO(kelkabany): We need to auto populate this as done in the v1 SDK.
6-
__version__ = '3.40'
6+
__version__ = '3.41'
77

88
import contextlib
99
import json

0 commit comments

Comments
 (0)