Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove six dependency #120

Merged
merged 1 commit into from Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions google/cloud/datastore/_gapic.py
Expand Up @@ -15,7 +15,7 @@
"""Helpers for making API requests via gapic / gRPC."""

from grpc import insecure_channel
import six
from urllib.parse import urlparse

from google.cloud._helpers import make_secure_channel
from google.cloud._http import DEFAULT_USER_AGENT
Expand All @@ -32,7 +32,7 @@ def make_datastore_api(client):
:rtype: :class:`.datastore.v1.datastore_client.DatastoreClient`
:returns: A datastore API instance with the proper credentials.
"""
parse_result = six.moves.urllib_parse.urlparse(client._base_url)
parse_result = urlparse(client._base_url)
host = parse_result.netloc
if parse_result.scheme == "https":
channel = make_secure_channel(client._credentials, DEFAULT_USER_AGENT, host)
Expand Down
11 changes: 5 additions & 6 deletions google/cloud/datastore/helpers.py
Expand Up @@ -22,7 +22,6 @@

from google.protobuf import struct_pb2
from google.type import latlng_pb2
import six

from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud.datastore_v1.types import datastore as datastore_pb2
Expand Down Expand Up @@ -105,7 +104,7 @@ def _property_tuples(entity_pb):
:returns: An iterator that yields tuples of a name and ``Value``
corresponding to properties on the entity.
"""
return six.iteritems(entity_pb.properties)
return iter(entity_pb.properties.items())


def entity_from_protobuf(pb):
Expand Down Expand Up @@ -206,7 +205,7 @@ def _set_pb_meaning_from_entity(entity, name, value, value_pb, is_list=False):
if is_list:
if not isinstance(meaning, list):
meaning = itertools.repeat(meaning)
val_iter = six.moves.zip(value_pb.array_value.values, meaning)
val_iter = zip(value_pb.array_value.values, meaning)
for sub_value_pb, sub_meaning in val_iter:
if sub_meaning is not None:
sub_value_pb.meaning = sub_meaning
Expand Down Expand Up @@ -359,11 +358,11 @@ def _pb_attr_value(val):
name, value = "boolean", val
elif isinstance(val, float):
name, value = "double", val
elif isinstance(val, six.integer_types):
elif isinstance(val, int):
name, value = "integer", val
elif isinstance(val, six.text_type):
elif isinstance(val, str):
name, value = "string", val
elif isinstance(val, six.binary_type):
elif isinstance(val, bytes):
name, value = "blob", val
elif isinstance(val, Entity):
name, value = "entity", val
Expand Down
11 changes: 5 additions & 6 deletions google/cloud/datastore/key.py
Expand Up @@ -16,7 +16,6 @@

import base64
import copy
import six

from google.cloud.datastore_v1.types import entity as _entity_pb2

Expand Down Expand Up @@ -185,14 +184,14 @@ def _parse_path(path_args):
result = []
for kind, id_or_name in zip(kind_list, id_or_name_list):
curr_key_part = {}
if isinstance(kind, six.string_types):
if isinstance(kind, str):
curr_key_part["kind"] = kind
else:
raise ValueError(kind, "Kind was not a string.")

if isinstance(id_or_name, six.string_types):
if isinstance(id_or_name, str):
curr_key_part["name"] = id_or_name
elif isinstance(id_or_name, six.integer_types):
elif isinstance(id_or_name, int):
curr_key_part["id"] = id_or_name
elif id_or_name is not partial_ending:
raise ValueError(id_or_name, "ID/name was not a string or integer.")
Expand Down Expand Up @@ -264,9 +263,9 @@ def completed_key(self, id_or_name):
if not self.is_partial:
raise ValueError("Only a partial key can be completed.")

if isinstance(id_or_name, six.string_types):
if isinstance(id_or_name, str):
id_or_name_key = "name"
elif isinstance(id_or_name, six.integer_types):
elif isinstance(id_or_name, int):
id_or_name_key = "id"
else:
raise ValueError(id_or_name, "ID/name was not a string or integer.")
Expand Down
7 changes: 3 additions & 4 deletions tests/system/test_system.py
Expand Up @@ -18,7 +18,6 @@
import warnings

import requests
import six

from google.cloud._helpers import UTC
from google.cloud import datastore
Expand Down Expand Up @@ -294,7 +293,7 @@ def test_limit_queries(self):

# Fetch characters.
iterator = query.fetch(limit=limit)
page = six.next(iterator.pages)
page = next(iterator.pages)
character_entities = list(page)
cursor = iterator.next_page_token
self.assertEqual(len(character_entities), limit)
Expand Down Expand Up @@ -442,7 +441,7 @@ def test_query_paginate_with_offset(self):
iterator = page_query.fetch(limit=limit, offset=offset)

# Fetch characters.
page = six.next(iterator.pages)
page = next(iterator.pages)
entities = list(page)
cursor = iterator.next_page_token
self.assertEqual(len(entities), limit)
Expand All @@ -466,7 +465,7 @@ def test_query_paginate_with_start_cursor(self):
iterator = page_query.fetch(limit=limit, offset=offset)

# Fetch characters.
page = six.next(iterator.pages)
page = next(iterator.pages)
entities = list(page)
cursor = iterator.next_page_token
self.assertEqual(len(entities), limit)
Expand Down
4 changes: 1 addition & 3 deletions tests/system/utils/clear_datastore.py
Expand Up @@ -19,8 +19,6 @@
import os
import sys

import six

from google.cloud import datastore


Expand Down Expand Up @@ -96,7 +94,7 @@ def main():

print_func("This command will remove all entities for " "the following kinds:")
print_func("\n".join("- " + val for val in kinds))
response = six.moves.input("Is this OK [y/n]? ")
response = input("Is this OK [y/n]? ")

if response.lower() == "y":

Expand Down
4 changes: 1 addition & 3 deletions tests/system/utils/populate_datastore.py
Expand Up @@ -23,8 +23,6 @@
import time
import uuid

import six

from google.cloud import datastore


Expand Down Expand Up @@ -121,7 +119,7 @@ def add_characters(client=None):
# Get a client that uses the test dataset.
client = datastore.Client()
with client.transaction() as xact:
for key_path, character in six.moves.zip(KEY_PATHS, CHARACTERS):
for key_path, character in zip(KEY_PATHS, CHARACTERS):
if key_path[-1] != character["name"]:
raise ValueError(("Character and key don't agree", key_path, character))
entity = datastore.Entity(key=client.key(*key_path))
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test__http.py
Expand Up @@ -15,7 +15,7 @@
import unittest

import mock
from six.moves import http_client
from http import client

import requests

Expand Down Expand Up @@ -72,7 +72,7 @@ def test_failure(self):
error.code = code_pb2.FAILED_PRECONDITION

http = _make_requests_session(
[_make_response(http_client.BAD_REQUEST, content=error.SerializeToString())]
[_make_response(client.BAD_REQUEST, content=error.SerializeToString())]
)

with self.assertRaises(BadRequest) as exc:
Expand Down Expand Up @@ -808,7 +808,7 @@ def test_allocate_ids_non_empty(self):
self.assertEqual(key_before, key_after)


def _make_response(status=http_client.OK, content=b"", headers={}):
def _make_response(status=client.OK, content=b"", headers={}):
response = requests.Response()
response.status_code = status
response._content = content
Expand Down