Repository: googleapis/google-cloud-python

Issue:
Pub/Sub: System test failures on Python 2.7 (invalid syntax)
https://source.cloud.google.com/results/invocations/e8706e96-9a37-40d5-8411-7cd62206b4aa/targets/cloud-devrel%2Fclient-libraries%2Fgoogle-cloud-python%2Fpresubmit%2Fpubsub/log

```
tests/unit/pubsub_v1/subscriber/test_subscriber_client.py:18: in <module>
    from google.cloud.pubsub_v1 import subscriber
google/cloud/pubsub_v1/__init__.py:19: in <module>
    from google.cloud.pubsub_v1 import subscriber
google/cloud/pubsub_v1/subscriber/__init__.py:17: in <module>
    from google.cloud.pubsub_v1.subscriber.client import Client
google/cloud/pubsub_v1/subscriber/client.py:30: in <module>
    from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
E     File "/tmpfs/src/github/google-cloud-python/pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 198
E       print(f"{messages_percent}, {bytes_percent}")
E                                                  ^
E   SyntaxError: invalid syntax
```

Looks like `streaming_pull_manager.py` is using a format string, which isn't valid Python 2.7 syntax. Needs to use `"{}, {}".format(...)`, instead.


Discussion:
How did that end up in the codebase, didn't the tests catch this before merging?

Anyhow, will have a look at it tomorrow, should be an easy fix. Thanks for bringing it up!
Found the [commit](https://github.com/googleapis/google-cloud-python/pull/7758/commits/b606d889f673b077fb43373c856c14e144d13991) that brought this in.

What are all those `print()` calls in `streaming_pull_manager.py` for anyway? They seem like some debugging leftovers to me...
I confirm those are bebugging leftover. They are safe to remove/reverted to what's there before. I was just noticing this one too and [commented](https://github.com/googleapis/google-cloud-python/commit/f5aec2d2fbb72d613abf5f2c99bdefc501b077d6#commitcomment-33381064) on the commit. 

Resolving patch:
diff --git a/pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py b/pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
--- a/pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
+++ b/pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
@@ -193,10 +193,12 @@ def load(self):
         if self._leaser is None:
             return 0
 
-        messages_percent = self._leaser.message_count / self._flow_control.max_messages
-        bytes_percent = self._leaser.bytes / self._flow_control.max_bytes
-        print(f"{messages_percent}, {bytes_percent}")
-        return max(messages_percent, bytes_percent)
+        return max(
+            [
+                self._leaser.message_count / self._flow_control.max_messages,
+                self._leaser.bytes / self._flow_control.max_bytes,
+            ]
+        )
 
     def add_close_callback(self, callback):
         """Schedules a callable when the manager closes.
@@ -208,12 +210,10 @@ def add_close_callback(self, callback):
 
     def maybe_pause_consumer(self):
         """Check the current load and pause the consumer if needed."""
-        print(self.load)
         if self.load >= 1.0:
             if self._consumer is not None and not self._consumer.is_paused:
                 _LOGGER.debug("Message backlog over load at %.2f, pausing.", self.load)
                 self._consumer.pause()
-                print('paused')
 
     def maybe_resume_consumer(self):
         """Check the current load and resume the consumer if needed."""
@@ -227,7 +227,6 @@ def maybe_resume_consumer(self):
             return
 
         if self.load < self.flow_control.resume_threshold:
-            print('resuming')
             self._consumer.resume()
         else:
             _LOGGER.debug("Did not resume, current load is %s", self.load)


Test patch:
diff --git a/pubsub/tests/system.py b/pubsub/tests/system.py
--- a/pubsub/tests/system.py
+++ b/pubsub/tests/system.py
@@ -65,6 +65,7 @@ def cleanup():
     for to_call, argument in registry:
         to_call(argument)
 
+
 def test_publish_messages(publisher, topic_path, cleanup):
     futures = []
     # Make sure the topic gets deleted.