Repository: googleapis/google-cloud-python

Issue:
Pycodestyle update causing our lint to fail.
From what I can tell, there are three new errors that pycodestyle is finding.

E306: expected 1 blank line before a nested definition, found 0
~E123: closing bracket does not match indentation of opening bracket's line~
~E722: do not use bare except~

See: #2973 


Discussion:

Resolving patch:
diff --git a/datastore/google/cloud/datastore/transaction.py b/datastore/google/cloud/datastore/transaction.py
--- a/datastore/google/cloud/datastore/transaction.py
+++ b/datastore/google/cloud/datastore/transaction.py
@@ -186,7 +186,7 @@ def begin(self):
         try:
             self._id = self._client._connection.begin_transaction(
                 self.project)
-        except:
+        except:  # noqa: E722 do not use bare except, specify exception instead
             self._status = self._ABORTED
             raise
 
diff --git a/dns/google/cloud/dns/changes.py b/dns/google/cloud/dns/changes.py
--- a/dns/google/cloud/dns/changes.py
+++ b/dns/google/cloud/dns/changes.py
@@ -188,14 +188,14 @@ def _build_resource(self):
             'type': added.record_type,
             'ttl': str(added.ttl),
             'rrdatas': added.rrdatas,
-            } for added in self.additions]
+        } for added in self.additions]
 
         deletions = [{
             'name': deleted.name,
             'type': deleted.record_type,
             'ttl': str(deleted.ttl),
             'rrdatas': deleted.rrdatas,
-            } for deleted in self.deletions]
+        } for deleted in self.deletions]
 
         return {
             'additions': additions,


Test patch:
diff --git a/bigquery/unit_tests/test_dataset.py b/bigquery/unit_tests/test_dataset.py
--- a/bigquery/unit_tests/test_dataset.py
+++ b/bigquery/unit_tests/test_dataset.py
@@ -838,7 +838,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/bigquery/unit_tests/test_job.py b/bigquery/unit_tests/test_job.py
--- a/bigquery/unit_tests/test_job.py
+++ b/bigquery/unit_tests/test_job.py
@@ -1904,7 +1904,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/bigquery/unit_tests/test_table.py b/bigquery/unit_tests/test_table.py
--- a/bigquery/unit_tests/test_table.py
+++ b/bigquery/unit_tests/test_table.py
@@ -1989,7 +1989,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/bigtable/unit_tests/test_instance.py b/bigtable/unit_tests/test_instance.py
--- a/bigtable/unit_tests/test_instance.py
+++ b/bigtable/unit_tests/test_instance.py
@@ -254,8 +254,8 @@ def test_create(self):
             metadata=Any(
                 type_url=type_url,
                 value=metadata.SerializeToString(),
-                )
             )
+        )
 
         # Patch the stub used by the API method.
         client._instance_stub = stub = _FakeStub(response_pb)
diff --git a/core/unit_tests/test_exceptions.py b/core/unit_tests/test_exceptions.py
--- a/core/unit_tests/test_exceptions.py
+++ b/core/unit_tests/test_exceptions.py
@@ -40,7 +40,7 @@ def test_ctor_explicit(self):
             'locationType': 'testing',
             'message': 'Testing',
             'reason': 'test',
-            }
+        }
         e = self._make_one('Testing', [ERROR])
         e.code = 600
         self.assertEqual(str(e), '600 Testing')
@@ -115,7 +115,7 @@ def test_miss_w_content_as_dict(self):
             'locationType': 'testing',
             'message': 'Testing',
             'reason': 'test',
-            }
+        }
         response = _Response(600)
         content = {"error": {"message": "Unknown Error", "errors": [ERROR]}}
         exception = self._call_fut(response, content)
diff --git a/datastore/unit_tests/test__http.py b/datastore/unit_tests/test__http.py
--- a/datastore/unit_tests/test__http.py
+++ b/datastore/unit_tests/test__http.py
@@ -1051,11 +1051,11 @@ def test_allocate_ids_non_empty(self):
         before_key_pbs = [
             self._make_key_pb(PROJECT, id_=None),
             self._make_key_pb(PROJECT, id_=None),
-            ]
+        ]
         after_key_pbs = [
             self._make_key_pb(PROJECT),
             self._make_key_pb(PROJECT, id_=2345),
-            ]
+        ]
         rsp_pb = datastore_pb2.AllocateIdsResponse()
         rsp_pb.keys.add().CopyFrom(after_key_pbs[0])
         rsp_pb.keys.add().CopyFrom(after_key_pbs[1])
diff --git a/datastore/unit_tests/test_batch.py b/datastore/unit_tests/test_batch.py
--- a/datastore/unit_tests/test_batch.py
+++ b/datastore/unit_tests/test_batch.py
@@ -121,7 +121,7 @@ def test_put_entity_w_completed_key(self):
             'baz': 'qux',
             'spam': [1, 2, 3],
             'frotz': [],  # will be ignored
-            }
+        }
         connection = _Connection()
         client = _Client(_PROJECT, connection)
         batch = self._make_one(client)
diff --git a/datastore/unit_tests/test_client.py b/datastore/unit_tests/test_client.py
--- a/datastore/unit_tests/test_client.py
+++ b/datastore/unit_tests/test_client.py
@@ -853,7 +853,7 @@ def test_query_explicit(self):
                 projection=PROJECTION,
                 order=ORDER,
                 distinct_on=DISTINCT_ON,
-                )
+            )
 
         self.assertIsInstance(query, _Dummy)
         self.assertEqual(query.args, (client,))
diff --git a/datastore/unit_tests/test_query.py b/datastore/unit_tests/test_query.py
--- a/datastore/unit_tests/test_query.py
+++ b/datastore/unit_tests/test_query.py
@@ -68,7 +68,7 @@ def test_ctor_explicit(self):
             projection=PROJECTION,
             order=ORDER,
             distinct_on=DISTINCT_ON,
-            )
+        )
         self.assertIs(query._client, client)
         self.assertEqual(query.project, _PROJECT)
         self.assertEqual(query.kind, _KIND)
diff --git a/dns/unit_tests/test_changes.py b/dns/unit_tests/test_changes.py
--- a/dns/unit_tests/test_changes.py
+++ b/dns/unit_tests/test_changes.py
@@ -347,7 +347,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/dns/unit_tests/test_zone.py b/dns/unit_tests/test_zone.py
--- a/dns/unit_tests/test_zone.py
+++ b/dns/unit_tests/test_zone.py
@@ -693,7 +693,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/resource_manager/unit_tests/test_project.py b/resource_manager/unit_tests/test_project.py
--- a/resource_manager/unit_tests/test_project.py
+++ b/resource_manager/unit_tests/test_project.py
@@ -362,7 +362,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/runtimeconfig/unit_tests/test_config.py b/runtimeconfig/unit_tests/test_config.py
--- a/runtimeconfig/unit_tests/test_config.py
+++ b/runtimeconfig/unit_tests/test_config.py
@@ -352,7 +352,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/runtimeconfig/unit_tests/test_variable.py b/runtimeconfig/unit_tests/test_variable.py
--- a/runtimeconfig/unit_tests/test_variable.py
+++ b/runtimeconfig/unit_tests/test_variable.py
@@ -198,7 +198,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response
diff --git a/storage/unit_tests/test_batch.py b/storage/unit_tests/test_batch.py
--- a/storage/unit_tests/test_batch.py
+++ b/storage/unit_tests/test_batch.py
@@ -40,7 +40,7 @@ def test_ctor_body_None(self):
         LINES = [
             "DELETE /path/to/api HTTP/1.1",
             "",
-            ]
+        ]
         mah = self._make_one(METHOD, PATH, {}, None)
         self.assertEqual(mah.get_content_type(), 'application/http')
         self.assertEqual(mah.get_payload().splitlines(), LINES)
@@ -56,7 +56,7 @@ def test_ctor_body_str(self):
             "Content-Type: text/plain",
             "",
             "ABC",
-            ]
+        ]
         mah = self._make_one(METHOD, PATH, HEADERS, BODY)
         self.assertEqual(mah.get_payload().splitlines(), LINES)
 
@@ -71,7 +71,7 @@ def test_ctor_body_dict(self):
             'Content-Type: application/json',
             '',
             '{"foo": "bar"}',
-            ]
+        ]
         mah = self._make_one(METHOD, PATH, HEADERS, BODY)
         self.assertEqual(mah.get_payload().splitlines(), LINES)
 
diff --git a/storage/unit_tests/test_bucket.py b/storage/unit_tests/test_bucket.py
--- a/storage/unit_tests/test_bucket.py
+++ b/storage/unit_tests/test_bucket.py
@@ -1098,7 +1098,7 @@ def api_request(self, **kw):
 
         try:
             response, self._responses = self._responses[0], self._responses[1:]
-        except:
+        except IndexError:
             raise NotFound('miss')
         else:
             return response