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

refactor: drop six package use #104

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 8 additions & 11 deletions google/cloud/firestore_v1/_helpers.py
Expand Up @@ -19,7 +19,6 @@
from google.protobuf import struct_pb2
from google.type import latlng_pb2
import grpc
import six

from google.cloud import exceptions
from google.cloud._helpers import _datetime_to_pb_timestamp
Expand Down Expand Up @@ -132,7 +131,7 @@ def verify_path(path, is_collection):
raise ValueError("A document must have an even number of path elements")

for element in path:
if not isinstance(element, six.string_types):
if not isinstance(element, str):
msg = BAD_PATH_TEMPLATE.format(element, type(element))
raise ValueError(msg)

Expand All @@ -155,11 +154,11 @@ def encode_value(value):
if value is None:
return document_pb2.Value(null_value=struct_pb2.NULL_VALUE)

# Must come before six.integer_types since ``bool`` is an integer subtype.
# Must come before int since ``bool`` is an integer subtype.
if isinstance(value, bool):
return document_pb2.Value(boolean_value=value)

if isinstance(value, six.integer_types):
if isinstance(value, int):
return document_pb2.Value(integer_value=value)

if isinstance(value, float):
Expand All @@ -171,10 +170,10 @@ def encode_value(value):
if isinstance(value, datetime.datetime):
return document_pb2.Value(timestamp_value=_datetime_to_pb_timestamp(value))

if isinstance(value, six.text_type):
if isinstance(value, str):
return document_pb2.Value(string_value=value)

if isinstance(value, six.binary_type):
if isinstance(value, bytes):
return document_pb2.Value(bytes_value=value)

# NOTE: We avoid doing an isinstance() check for a Document
Expand Down Expand Up @@ -212,7 +211,7 @@ def encode_dict(values_dict):
dictionary of string keys and ``Value`` protobufs as dictionary
values.
"""
return {key: encode_value(value) for key, value in six.iteritems(values_dict)}
return {key: encode_value(value) for key, value in values_dict.items()}


def reference_value_to_document(reference_value, client):
Expand Down Expand Up @@ -309,9 +308,7 @@ def decode_dict(value_fields, client):
str, bytes, dict, ~google.cloud.Firestore.GeoPoint]]: A dictionary
of native Python values converted from the ``value_fields``.
"""
return {
key: decode_value(value, client) for key, value in six.iteritems(value_fields)
}
return {key: decode_value(value, client) for key, value in value_fields.items()}


def get_doc_id(document_pb, expected_prefix):
Expand Down Expand Up @@ -350,7 +347,7 @@ def extract_fields(document_data, prefix_path, expand_dots=False):
if not document_data:
yield prefix_path, _EmptyDict
else:
for key, value in sorted(six.iteritems(document_data)):
for key, value in sorted(document_data.items()):

if expand_dots:
sub_key = FieldPath.from_string(key)
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1/collection.py
Expand Up @@ -15,8 +15,6 @@
"""Classes for representing collections for the Google Cloud Firestore API."""
import random

import six

from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1 import query as query_mod
from google.cloud.firestore_v1.watch import Watch
Expand Down Expand Up @@ -494,7 +492,7 @@ def _auto_id():
str: A 20 character string composed of digits, uppercase and
lowercase and letters.
"""
return "".join(random.choice(_AUTO_ID_CHARS) for _ in six.moves.xrange(20))
return "".join(random.choice(_AUTO_ID_CHARS) for _ in range(20))


def _item_to_document_ref(iterator, item):
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1/document.py
Expand Up @@ -16,8 +16,6 @@

import copy

import six

from google.api_core import exceptions
from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1 import field_path as field_path_module
Expand Down Expand Up @@ -434,7 +432,7 @@ def get(self, field_paths=None, transaction=None):
:attr:`create_time` attributes will all be ``None`` and
its :attr:`exists` attribute will be ``False``.
"""
if isinstance(field_paths, six.string_types):
if isinstance(field_paths, str):
raise ValueError("'field_paths' must be a sequence of paths, not a string.")

if field_paths is not None:
Expand Down
8 changes: 3 additions & 5 deletions google/cloud/firestore_v1/field_path.py
Expand Up @@ -21,8 +21,6 @@

import re

import six


_FIELD_PATH_MISSING_TOP = "{!r} is not contained in the data"
_FIELD_PATH_MISSING_KEY = "{!r} is not contained in the data for the key {!r}"
Expand Down Expand Up @@ -271,7 +269,7 @@ class FieldPath(object):

def __init__(self, *parts):
for part in parts:
if not isinstance(part, six.string_types) or not part:
if not isinstance(part, str) or not part:
error = "One or more components is not a string or is empty."
raise ValueError(error)
self.parts = tuple(parts)
Expand Down Expand Up @@ -353,7 +351,7 @@ def __add__(self, other):
if isinstance(other, FieldPath):
parts = self.parts + other.parts
return FieldPath(*parts)
elif isinstance(other, six.string_types):
elif isinstance(other, str):
parts = self.parts + FieldPath.from_string(other).parts
return FieldPath(*parts)
else:
Expand Down Expand Up @@ -382,7 +380,7 @@ def lineage(self):

Returns: Set[:class:`FieldPath`]
"""
indexes = six.moves.range(1, len(self.parts))
indexes = range(1, len(self.parts))
return {FieldPath(*self.parts[:index]) for index in indexes}

@staticmethod
Expand Down
3 changes: 1 addition & 2 deletions google/cloud/firestore_v1/query.py
Expand Up @@ -22,7 +22,6 @@
import math

from google.protobuf import wrappers_pb2
import six

from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1 import document
Expand Down Expand Up @@ -745,7 +744,7 @@ def _normalize_cursor(self, cursor, orders):
msg = _INVALID_CURSOR_TRANSFORM
raise ValueError(msg)

if key == "__name__" and isinstance(field, six.string_types):
if key == "__name__" and isinstance(field, str):
document_fields[index] = self._parent.document(field)

return document_fields, before
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1/transaction.py
Expand Up @@ -18,8 +18,6 @@
import random
import time

import six

from google.api_core import exceptions
from google.cloud.firestore_v1 import batch
from google.cloud.firestore_v1 import types
Expand Down Expand Up @@ -344,7 +342,7 @@ def __call__(self, transaction, *args, **kwargs):
"""
self._reset()

for attempt in six.moves.xrange(transaction._max_attempts):
for attempt in range(transaction._max_attempts):
result = self._pre_commit(transaction, *args, **kwargs)
succeeded = self._maybe_commit(transaction)
if succeeded:
Expand Down
19 changes: 8 additions & 11 deletions google/cloud/firestore_v1beta1/_helpers.py
Expand Up @@ -19,7 +19,6 @@
from google.protobuf import struct_pb2
from google.type import latlng_pb2
import grpc
import six

from google.cloud import exceptions
from google.cloud._helpers import _datetime_to_pb_timestamp
Expand Down Expand Up @@ -132,7 +131,7 @@ def verify_path(path, is_collection):
raise ValueError("A document must have an even number of path elements")

for element in path:
if not isinstance(element, six.string_types):
if not isinstance(element, str):
msg = BAD_PATH_TEMPLATE.format(element, type(element))
raise ValueError(msg)

Expand All @@ -155,11 +154,11 @@ def encode_value(value):
if value is None:
return document_pb2.Value(null_value=struct_pb2.NULL_VALUE)

# Must come before six.integer_types since ``bool`` is an integer subtype.
# Must come before int since ``bool`` is an integer subtype.
if isinstance(value, bool):
return document_pb2.Value(boolean_value=value)

if isinstance(value, six.integer_types):
if isinstance(value, int):
return document_pb2.Value(integer_value=value)

if isinstance(value, float):
Expand All @@ -171,10 +170,10 @@ def encode_value(value):
if isinstance(value, datetime.datetime):
return document_pb2.Value(timestamp_value=_datetime_to_pb_timestamp(value))

if isinstance(value, six.text_type):
if isinstance(value, str):
return document_pb2.Value(string_value=value)

if isinstance(value, six.binary_type):
if isinstance(value, bytes):
return document_pb2.Value(bytes_value=value)

# NOTE: We avoid doing an isinstance() check for a Document
Expand Down Expand Up @@ -212,7 +211,7 @@ def encode_dict(values_dict):
dictionary of string keys and ``Value`` protobufs as dictionary
values.
"""
return {key: encode_value(value) for key, value in six.iteritems(values_dict)}
return {key: encode_value(value) for key, value in values_dict.items()}


def reference_value_to_document(reference_value, client):
Expand Down Expand Up @@ -309,9 +308,7 @@ def decode_dict(value_fields, client):
str, bytes, dict, ~google.cloud.Firestore.GeoPoint]]: A dictionary
of native Python values converted from the ``value_fields``.
"""
return {
key: decode_value(value, client) for key, value in six.iteritems(value_fields)
}
return {key: decode_value(value, client) for key, value in value_fields.items()}


def get_doc_id(document_pb, expected_prefix):
Expand Down Expand Up @@ -350,7 +347,7 @@ def extract_fields(document_data, prefix_path, expand_dots=False):
if not document_data:
yield prefix_path, _EmptyDict
else:
for key, value in sorted(six.iteritems(document_data)):
for key, value in sorted(document_data.items()):

if expand_dots:
sub_key = FieldPath.from_string(key)
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1beta1/collection.py
Expand Up @@ -16,8 +16,6 @@
import random
import warnings

import six

from google.cloud.firestore_v1beta1 import _helpers
from google.cloud.firestore_v1beta1 import query as query_mod
from google.cloud.firestore_v1beta1.proto import document_pb2
Expand Down Expand Up @@ -463,7 +461,7 @@ def _auto_id():
str: A 20 character string composed of digits, uppercase and
lowercase and letters.
"""
return "".join(random.choice(_AUTO_ID_CHARS) for _ in six.moves.xrange(20))
return "".join(random.choice(_AUTO_ID_CHARS) for _ in range(20))


def _item_to_document_ref(iterator, item):
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1beta1/document.py
Expand Up @@ -16,8 +16,6 @@

import copy

import six

from google.api_core import exceptions
from google.cloud.firestore_v1beta1 import _helpers
from google.cloud.firestore_v1beta1 import field_path as field_path_module
Expand Down Expand Up @@ -431,7 +429,7 @@ def get(self, field_paths=None, transaction=None):
`update_time`, and `create_time` attributes will all be
`None` and `exists` will be `False`.
"""
if isinstance(field_paths, six.string_types):
if isinstance(field_paths, str):
raise ValueError("'field_paths' must be a sequence of paths, not a string.")

if field_paths is not None:
Expand Down
8 changes: 3 additions & 5 deletions google/cloud/firestore_v1beta1/field_path.py
Expand Up @@ -21,8 +21,6 @@

import re

import six


_FIELD_PATH_MISSING_TOP = "{!r} is not contained in the data"
_FIELD_PATH_MISSING_KEY = "{!r} is not contained in the data for the key {!r}"
Expand Down Expand Up @@ -271,7 +269,7 @@ class FieldPath(object):

def __init__(self, *parts):
for part in parts:
if not isinstance(part, six.string_types) or not part:
if not isinstance(part, str) or not part:
error = "One or more components is not a string or is empty."
raise ValueError(error)
self.parts = tuple(parts)
Expand Down Expand Up @@ -353,7 +351,7 @@ def __add__(self, other):
if isinstance(other, FieldPath):
parts = self.parts + other.parts
return FieldPath(*parts)
elif isinstance(other, six.string_types):
elif isinstance(other, str):
parts = self.parts + FieldPath.from_string(other).parts
return FieldPath(*parts)
else:
Expand Down Expand Up @@ -382,5 +380,5 @@ def lineage(self):

Returns: Set[:class:`FieldPath`]
"""
indexes = six.moves.range(1, len(self.parts))
indexes = range(1, len(self.parts))
return {FieldPath(*self.parts[:index]) for index in indexes}
3 changes: 1 addition & 2 deletions google/cloud/firestore_v1beta1/query.py
Expand Up @@ -24,7 +24,6 @@
import warnings

from google.protobuf import wrappers_pb2
import six

from google.cloud.firestore_v1beta1 import _helpers
from google.cloud.firestore_v1beta1 import document
Expand Down Expand Up @@ -659,7 +658,7 @@ def _normalize_cursor(self, cursor, orders):
msg = _INVALID_CURSOR_TRANSFORM
raise ValueError(msg)

if key == "__name__" and isinstance(field, six.string_types):
if key == "__name__" and isinstance(field, str):
document_fields[index] = self._parent.document(field)

return document_fields, before
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/firestore_v1beta1/transaction.py
Expand Up @@ -18,8 +18,6 @@
import random
import time

import six

from google.api_core import exceptions
from google.cloud.firestore_v1beta1 import batch
from google.cloud.firestore_v1beta1 import types
Expand Down Expand Up @@ -310,7 +308,7 @@ def __call__(self, transaction, *args, **kwargs):
"""
self._reset()

for attempt in six.moves.xrange(transaction._max_attempts):
for attempt in range(transaction._max_attempts):
result = self._pre_commit(transaction, *args, **kwargs)
succeeded = self._maybe_commit(transaction)
if succeeded:
Expand Down