Skip to content

Commit a54d078

Browse files
committed
PEP257 Clean-up of docstrings.
Fixes all Pylint failures of - missing-returns-doc - redundant-returns-doc - ungrouped-imports Also makes a little headway on missing-raises-doc though it's unclear if this error should be fixed. Towards googleapis#1968.
1 parent d171791 commit a54d078

39 files changed

+198
-72
lines changed

gcloud/_helpers.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@
2626
from threading import local as Local
2727

2828
from google.protobuf import timestamp_pb2
29+
try:
30+
from google.appengine.api import app_identity
31+
except ImportError:
32+
app_identity = None
2933
import six
3034
from six.moves.http_client import HTTPConnection
3135
from six.moves import configparser
3236

3337
from gcloud.environment_vars import PROJECT
3438
from gcloud.environment_vars import CREDENTIALS
3539

36-
try:
37-
from google.appengine.api import app_identity
38-
except ImportError:
39-
app_identity = None
40-
4140

4241
_NOW = datetime.datetime.utcnow # To be replaced by tests.
4342
_RFC3339_MICROS = '%Y-%m-%dT%H:%M:%S.%fZ'
@@ -77,15 +76,17 @@ def push(self, resource):
7776
def pop(self):
7877
"""Pop a resource from our stack.
7978
80-
:raises: IndexError if the stack is empty.
79+
:rtype: object
8180
:returns: the top-most resource, after removing it.
81+
:raises IndexError: if the stack is empty.
8282
"""
8383
return self._stack.pop()
8484

8585
@property
8686
def top(self):
8787
"""Get the top-most resource
8888
89+
:rtype: object
8990
:returns: the top-most item, or None if the stack is empty.
9091
"""
9192
if len(self._stack) > 0:
@@ -141,8 +142,7 @@ def _ensure_tuple_or_list(arg_name, tuple_or_list):
141142
142143
:rtype: list of str
143144
:returns: The ``tuple_or_list`` passed in cast to a ``list``.
144-
:raises: class:`TypeError` if the ``tuple_or_list`` is not a tuple or
145-
list.
145+
:raises TypeError: if the ``tuple_or_list`` is not a tuple or list.
146146
"""
147147
if not isinstance(tuple_or_list, (tuple, list)):
148148
raise TypeError('Expected %s to be a tuple or list. '
@@ -392,6 +392,8 @@ def _rfc3339_nanos_to_datetime(dt_str):
392392
393393
:rtype: :class:`datetime.datetime`
394394
:returns: The datetime object created from the string.
395+
:raises ValueError: If the timestamp does not match the RFC 3339
396+
regular expression.
395397
"""
396398
with_nanos = _RFC3339_NANOS.match(dt_str)
397399
if with_nanos is None:
@@ -439,8 +441,7 @@ def _to_bytes(value, encoding='ascii'):
439441
:rtype: str / bytes
440442
:returns: The original value converted to bytes (if unicode) or as passed
441443
in if it started out as bytes.
442-
:raises: :class:`TypeError <exceptions.TypeError>` if the value
443-
could not be converted to bytes.
444+
:raises TypeError: if the value could not be converted to bytes.
444445
"""
445446
result = (value.encode(encoding)
446447
if isinstance(value, six.text_type) else value)
@@ -460,8 +461,7 @@ def _bytes_to_unicode(value):
460461
:returns: The original value converted to unicode (if bytes) or as passed
461462
in if it started out as unicode.
462463
463-
:raises: :class:`ValueError` if the value could not be converted to
464-
unicode.
464+
:raises ValueError: if the value could not be converted to unicode.
465465
"""
466466
result = (value.decode('utf-8')
467467
if isinstance(value, six.binary_type) else value)
@@ -522,9 +522,9 @@ def _name_from_project_path(path, project, template):
522522
523523
:rtype: str
524524
:returns: Name parsed from ``path``.
525-
:raises: :class:`ValueError` if the ``path`` is ill-formed or if
526-
the project from the ``path`` does not agree with the
527-
``project`` passed in.
525+
:raises ValueError: if the ``path`` is ill-formed or if the project from
526+
the ``path`` does not agree with the ``project``
527+
passed in.
528528
"""
529529
if isinstance(template, str):
530530
template = re.compile(template)

gcloud/bigquery/dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ def exists(self, client=None):
432432
:type client: :class:`gcloud.bigquery.client.Client` or ``NoneType``
433433
:param client: the client to use. If not passed, falls back to the
434434
``client`` stored on the current dataset.
435+
436+
:rtype: bool
437+
:returns: Boolean indicating existence of the dataset.
435438
"""
436439
client = self._require_client(client)
437440

gcloud/bigquery/job.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def exists(self, client=None):
319319
:type client: :class:`gcloud.bigquery.client.Client` or ``NoneType``
320320
:param client: the client to use. If not passed, falls back to the
321321
``client`` stored on the current dataset.
322+
323+
:rtype: bool
324+
:returns: Boolean indicating existence of the job.
322325
"""
323326
client = self._require_client(client)
324327

gcloud/bigquery/table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ def exists(self, client=None):
461461
:type client: :class:`gcloud.bigquery.client.Client` or ``NoneType``
462462
:param client: the client to use. If not passed, falls back to the
463463
``client`` stored on the current dataset.
464+
465+
:rtype: bool
466+
:returns: Boolean indicating existence of the table.
464467
"""
465468
client = self._require_client(client)
466469

gcloud/bigtable/happybase/connection.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def _get_instance(timeout=None):
7171
:rtype: :class:`gcloud.bigtable.instance.Instance`
7272
:returns: The unique instance owned by the project inferred from
7373
the environment.
74-
:raises: :class:`ValueError <exceptions.ValueError>` if there is a failed
75-
location or any number of instances other than one.
74+
:raises ValueError: if there is a failed location or any number of
75+
instances other than one.
7676
"""
7777
client_kwargs = {'admin': True}
7878
if timeout is not None:
@@ -182,9 +182,8 @@ def _handle_legacy_args(arguments_dict):
182182
:type arguments_dict: dict
183183
:param arguments_dict: Unused keyword arguments.
184184
185-
:raises: :class:`TypeError <exceptions.TypeError>` if a keyword other
186-
than ``host``, ``port``, ``compat``, ``transport`` or
187-
``protocol`` is used.
185+
:raises TypeError: if a keyword other than ``host``, ``port``,
186+
``compat``, ``transport`` or ``protocol`` is used.
188187
"""
189188
common_args = _LEGACY_ARGS.intersection(six.iterkeys(arguments_dict))
190189
if common_args:
@@ -322,10 +321,12 @@ def create_table(self, name, families):
322321
* :class:`dict`
323322
* :class:`.GarbageCollectionRule`
324323
325-
:raises: :class:`TypeError <exceptions.TypeError>` if ``families`` is
326-
not a dictionary,
327-
:class:`ValueError <exceptions.ValueError>` if ``families``
328-
has no entries
324+
:raises TypeError: If ``families`` is not a dictionary.
325+
:raises ValueError: If ``families`` has no entries.
326+
:raises AlreadyExists: If creation fails due to an already
327+
existing table.
328+
:raises NetworkError: If creation fails for a reason other than
329+
table exists.
329330
"""
330331
if not isinstance(families, dict):
331332
raise TypeError('families arg must be a dictionary')

gcloud/bigtable/happybase/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ def connection(self, timeout=None):
113113
If ``timeout`` is omitted, this method waits forever for a connection
114114
to become available from the local queue.
115115
116+
Yields an active :class:`Connection <.happybase.connection.Connection>`
117+
from the pool.
118+
116119
:type timeout: int
117120
:param timeout: (Optional) Time (in seconds) to wait for a connection
118121
to open.
119122
120-
:rtype: :class:`Connection <.happybase.connection.Connection>`
121-
:returns: An active connection from the pool.
122123
:raises: :class:`NoConnectionsAvailable` if no connection can be
123124
retrieved from the pool before the ``timeout`` (only if
124125
a timeout is specified).

gcloud/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ def api_request(self, method, path, query_params=None,
324324
initialization of the object at a later time.
325325
326326
:raises: Exception if the response code is not 200 OK.
327+
:rtype: dict or str
328+
:returns: The API response payload, either as a raw string or
329+
a dictionary if the response is valid JSON.
327330
"""
328331
url = self.build_api_url(path=path, query_params=query_params,
329332
api_base_url=api_base_url,

gcloud/datastore/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def delete(self, key):
366366
:type key: :class:`gcloud.datastore.key.Key`
367367
:param key: The key to be deleted from the datastore.
368368
"""
369-
return self.delete_multi(keys=[key])
369+
self.delete_multi(keys=[key])
370370

371371
def delete_multi(self, keys):
372372
"""Delete keys from the Cloud Datastore.

gcloud/datastore/connection.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ def _rpc(self, project, method, request_pb, response_pb_cls):
112112
:type request_pb: :class:`google.protobuf.message.Message` instance
113113
:param request_pb: the protobuf instance representing the request.
114114
115-
:type response_pb_cls: A :class:`google.protobuf.message.Message'
115+
:type response_pb_cls: A :class:`google.protobuf.message.Message`
116116
subclass.
117117
:param response_pb_cls: The class used to unmarshall the response
118118
protobuf.
119+
120+
:rtype: :class:`google.protobuf.message.Message`
121+
:returns: The RPC message parsed from the response.
119122
"""
120123
response = self._request(project=project, method=method,
121124
data=request_pb.SerializeToString())
@@ -142,6 +145,9 @@ def build_api_url(self, project, method, base_url=None,
142145
:type api_version: string
143146
:param api_version: The version of the API to connect to.
144147
You shouldn't have to provide this.
148+
149+
:rtype: str
150+
:returns: The API URL created.
145151
"""
146152
return self.API_URL_TEMPLATE.format(
147153
api_base=(base_url or self.api_base_url),
@@ -322,9 +328,9 @@ def commit(self, project, request, transaction_id):
322328
This method will mutate ``request`` before using it.
323329
324330
:rtype: tuple
325-
:returns': The pair of the number of index updates and a list of
326-
:class:`._generated.entity_pb2.Key` for each incomplete key
327-
that was completed in the commit.
331+
:returns: The pair of the number of index updates and a list of
332+
:class:`._generated.entity_pb2.Key` for each incomplete key
333+
that was completed in the commit.
328334
"""
329335
if transaction_id:
330336
request.mode = _datastore_pb2.CommitRequest.TRANSACTIONAL
@@ -415,9 +421,9 @@ def _parse_commit_response(commit_response_pb):
415421
:param commit_response_pb: The protobuf response from a commit request.
416422
417423
:rtype: tuple
418-
:returns': The pair of the number of index updates and a list of
419-
:class:`._generated.entity_pb2.Key` for each incomplete key
420-
that was completed in the commit.
424+
:returns: The pair of the number of index updates and a list of
425+
:class:`._generated.entity_pb2.Key` for each incomplete key
426+
that was completed in the commit.
421427
"""
422428
mut_results = commit_response_pb.mutation_results
423429
index_updates = commit_response_pb.index_updates

gcloud/datastore/entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def exclude_from_indexes(self):
131131
"""Names of fields which are *not* to be indexed for this entity.
132132
133133
:rtype: sequence of field names
134+
:returns: The set of fields excluded from indexes.
134135
"""
135136
return frozenset(self._exclude_from_indexes)
136137

gcloud/datastore/helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def _pb_attr_value(val):
296296
bool, float, integer, string
297297
:param val: The value to be scrutinized.
298298
299+
:rtype: tuple
299300
:returns: A tuple of the attribute name and proper value type.
300301
"""
301302

@@ -341,6 +342,7 @@ def _get_value_from_value_pb(value_pb):
341342
:type value_pb: :class:`gcloud.datastore._generated.entity_pb2.Value`
342343
:param value_pb: The Value Protobuf.
343344
345+
:rtype: object
344346
:returns: The value provided by the Protobuf.
345347
:raises: :class:`ValueError <exceptions.ValueError>` if no value type
346348
has been set.

gcloud/datastore/query.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def project(self):
101101
"""Get the project for this Query.
102102
103103
:rtype: str
104+
:returns: The project for the query.
104105
"""
105106
return self._project or self._client.project
106107

@@ -128,6 +129,7 @@ def kind(self):
128129
"""Get the Kind of the Query.
129130
130131
:rtype: string
132+
:returns: The kind for the query.
131133
"""
132134
return self._kind
133135

@@ -155,6 +157,7 @@ def ancestor(self):
155157
"""The ancestor key for the query.
156158
157159
:rtype: Key or None
160+
:returns: The ancestor for the query.
158161
"""
159162
return self._ancestor
160163

@@ -179,6 +182,7 @@ def filters(self):
179182
"""Filters set on the query.
180183
181184
:rtype: sequence of (property_name, operator, value) tuples.
185+
:returns: The filters set on the query.
182186
"""
183187
return self._filters[:]
184188

@@ -267,6 +271,7 @@ def order(self):
267271
"""Names of fields used to sort query results.
268272
269273
:rtype: sequence of string
274+
:returns: The order(s) set on the query.
270275
"""
271276
return self._order[:]
272277

@@ -291,6 +296,7 @@ def distinct_on(self):
291296
"""Names of fields used to group query results.
292297
293298
:rtype: sequence of string
299+
:returns: The "distinct on" fields set on the query.
294300
"""
295301
return self._distinct_on[:]
296302

@@ -338,6 +344,7 @@ def fetch(self, limit=None, offset=0, start_cursor=None, end_cursor=None,
338344
If not supplied, uses the query's value.
339345
340346
:rtype: :class:`Iterator`
347+
:returns: The iterator for the query.
341348
:raises: ValueError if ``connection`` is not passed and no implicit
342349
default has been set.
343350
"""
@@ -400,6 +407,7 @@ def next_page(self):
400407
to iterate on the current Iterator.
401408
402409
:rtype: tuple, (entities, more_results, cursor)
410+
:returns: The next page of results.
403411
"""
404412
pb = _pb_from_query(self._query)
405413

gcloud/datastore/transaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def current(self):
112112
returns None.
113113
114114
:rtype: :class:`gcloud.datastore.transaction.Transaction` or None
115+
:returns: The current transaction (if any are active).
115116
"""
116117
top = super(Transaction, self).current()
117118
if isinstance(top, Transaction):

gcloud/dns/changes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def exists(self, client=None):
229229
:type client: :class:`gcloud.dns.client.Client` or ``NoneType``
230230
:param client: the client to use. If not passed, falls back to the
231231
``client`` stored on the current zone.
232+
233+
:rtype: bool
234+
:returns: Boolean indicating existence of the changes.
232235
"""
233236
client = self._require_client(client)
234237
try:

gcloud/dns/zone.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ def exists(self, client=None):
267267
:type client: :class:`gcloud.dns.client.Client` or ``NoneType``
268268
:param client: the client to use. If not passed, falls back to the
269269
``client`` stored on the current zone.
270+
271+
:rtype: bool
272+
:returns: Boolean indicating existence of the managed zone.
270273
"""
271274
client = self._require_client(client)
272275

gcloud/iterator.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ def get_items_from_response(self, response):
136136
137137
:type response: dict
138138
:param response: The response of asking for the next page of items.
139-
140-
:rtype: iterable
141-
:returns: Items that the iterator should yield.
142139
"""
143140
raise NotImplementedError
144141

0 commit comments

Comments
 (0)