Skip to content

Commit 35ba7d3

Browse files
committed
chore: remove other Python 2.7 workarounds
1 parent 35c8216 commit 35ba7d3

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

google/api_core/gapic_v1/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import sys
16-
1715
from google.api_core.gapic_v1 import client_info
1816
from google.api_core.gapic_v1 import config
17+
from google.api_core.gapic_v1 import config_async
1918
from google.api_core.gapic_v1 import method
19+
from google.api_core.gapic_v1 import method_async
2020
from google.api_core.gapic_v1 import routing_header
2121

22-
__all__ = ["client_info", "config", "method", "routing_header"]
23-
24-
if sys.version_info >= (3, 6):
25-
from google.api_core.gapic_v1 import config_async # noqa: F401
26-
from google.api_core.gapic_v1 import method_async # noqa: F401
27-
__all__.append("config_async")
28-
__all__.append("method_async")
22+
__all__ = [
23+
"client_info",
24+
"config",
25+
"config_async",
26+
"method",
27+
"method_async",
28+
"routing_header",
29+
]

google/api_core/gapic_v1/routing_header.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
Generally, these headers are specified as gRPC metadata.
2121
"""
2222

23-
import sys
2423
from urllib.parse import urlencode
2524

2625
ROUTING_METADATA_KEY = "x-goog-request-params"
@@ -36,9 +35,6 @@ def to_routing_header(params):
3635
Returns:
3736
str: The routing header string.
3837
"""
39-
if sys.version_info[0] < 3:
40-
# Python 2 does not have the "safe" parameter for urlencode.
41-
return urlencode(params).replace("%2F", "/")
4238
return urlencode(
4339
params,
4440
# Per Google API policy (go/api-url-encoding), / is not encoded.

google/api_core/iam.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@
5252
"""
5353

5454
import collections
55+
import collections.abc
5556
import operator
5657
import warnings
5758

58-
try:
59-
from collections import abc as collections_abc
60-
except ImportError: # Python 2.7
61-
import collections as collections_abc
62-
6359
# Generic IAM roles
6460

6561
OWNER_ROLE = "roles/owner"
@@ -87,7 +83,7 @@ class InvalidOperationException(Exception):
8783
pass
8884

8985

90-
class Policy(collections_abc.MutableMapping):
86+
class Policy(collections.abc.MutableMapping):
9187
"""IAM Policy
9288
9389
Args:
@@ -450,10 +446,7 @@ def to_api_repr(self):
450446
for binding in self._bindings:
451447
members = binding.get("members")
452448
if members:
453-
new_binding = {
454-
"role": binding["role"],
455-
"members": sorted(members)
456-
}
449+
new_binding = {"role": binding["role"], "members": sorted(members)}
457450
condition = binding.get("condition")
458451
if condition:
459452
new_binding["condition"] = condition

google/api_core/operations_v1/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
"""Package for interacting with the google.longrunning.operations meta-API."""
1616

17-
import sys
18-
17+
from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient
1918
from google.api_core.operations_v1.operations_client import OperationsClient
2019

21-
__all__ = ["OperationsClient"]
22-
if sys.version_info >= (3, 6, 0):
23-
from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient # noqa: F401
24-
__all__.append("OperationsAsyncClient")
20+
__all__ = ["OperationsAsyncClient", "OperationsClient"]

google/api_core/protobuf_helpers.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515
"""Helpers for :mod:`protobuf`."""
1616

1717
import collections
18+
import collections.abc
1819
import copy
1920
import inspect
2021

2122
from google.protobuf import field_mask_pb2
2223
from google.protobuf import message
2324
from google.protobuf import wrappers_pb2
2425

25-
try:
26-
from collections import abc as collections_abc
27-
except ImportError: # Python 2.7
28-
import collections as collections_abc
29-
3026

3127
_SENTINEL = object()
3228
_WRAPPER_TYPES = (
@@ -179,7 +175,7 @@ def get(msg_or_dict, key, default=_SENTINEL):
179175
# If we get something else, complain.
180176
if isinstance(msg_or_dict, message.Message):
181177
answer = getattr(msg_or_dict, key, default)
182-
elif isinstance(msg_or_dict, collections_abc.Mapping):
178+
elif isinstance(msg_or_dict, collections.abc.Mapping):
183179
answer = msg_or_dict.get(key, default)
184180
else:
185181
raise TypeError(
@@ -204,21 +200,21 @@ def _set_field_on_message(msg, key, value):
204200
"""Set helper for protobuf Messages."""
205201
# Attempt to set the value on the types of objects we know how to deal
206202
# with.
207-
if isinstance(value, (collections_abc.MutableSequence, tuple)):
203+
if isinstance(value, (collections.abc.MutableSequence, tuple)):
208204
# Clear the existing repeated protobuf message of any elements
209205
# currently inside it.
210206
while getattr(msg, key):
211207
getattr(msg, key).pop()
212208

213209
# Write our new elements to the repeated field.
214210
for item in value:
215-
if isinstance(item, collections_abc.Mapping):
211+
if isinstance(item, collections.abc.Mapping):
216212
getattr(msg, key).add(**item)
217213
else:
218214
# protobuf's RepeatedCompositeContainer doesn't support
219215
# append.
220216
getattr(msg, key).extend([item])
221-
elif isinstance(value, collections_abc.Mapping):
217+
elif isinstance(value, collections.abc.Mapping):
222218
# Assign the dictionary values to the protobuf message.
223219
for item_key, item_value in value.items():
224220
set(getattr(msg, key), item_key, item_value)
@@ -241,7 +237,7 @@ def set(msg_or_dict, key, value):
241237
TypeError: If ``msg_or_dict`` is not a Message or dictionary.
242238
"""
243239
# Sanity check: Is our target object valid?
244-
if not isinstance(msg_or_dict, (collections_abc.MutableMapping, message.Message)):
240+
if not isinstance(msg_or_dict, (collections.abc.MutableMapping, message.Message)):
245241
raise TypeError(
246242
"set() expected a dict or protobuf message, got {!r}.".format(
247243
type(msg_or_dict)
@@ -254,12 +250,12 @@ def set(msg_or_dict, key, value):
254250
# If a subkey exists, then get that object and call this method
255251
# recursively against it using the subkey.
256252
if subkey is not None:
257-
if isinstance(msg_or_dict, collections_abc.MutableMapping):
253+
if isinstance(msg_or_dict, collections.abc.MutableMapping):
258254
msg_or_dict.setdefault(basekey, {})
259255
set(get(msg_or_dict, basekey), subkey, value)
260256
return
261257

262-
if isinstance(msg_or_dict, collections_abc.MutableMapping):
258+
if isinstance(msg_or_dict, collections.abc.MutableMapping):
263259
msg_or_dict[key] = value
264260
else:
265261
_set_field_on_message(msg_or_dict, key, value)

0 commit comments

Comments
 (0)