Skip to content

Commit

Permalink
Removed remaining dependence on six for Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed Sep 9, 2021
1 parent a76f5da commit c70b4e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 1 addition & 3 deletions python/google/protobuf/internal/_parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ def testIsNegative(self, arg):
import unittest
import uuid

import six

try:
# Since python 3
import collections.abc as collections_abc
Expand All @@ -181,7 +179,7 @@ def _StrClass(cls):

def _NonStringIterable(obj):
return (isinstance(obj, collections_abc.Iterable) and not
isinstance(obj, six.string_types))
isinstance(obj, str))


def _FormatParameterList(testcase_params):
Expand Down
14 changes: 5 additions & 9 deletions python/google/protobuf/internal/well_known_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import calendar
from datetime import datetime
from datetime import timedelta
import six

try:
# Since python 3
Expand Down Expand Up @@ -143,7 +142,7 @@ def FromJsonString(self, value):
Raises:
ValueError: On parsing problems.
"""
if not isinstance(value, six.string_types):
if not isinstance(value, str):
raise ValueError('Timestamp JSON value not a string: {!r}'.format(value))
timezone_offset = value.find('Z')
if timezone_offset == -1:
Expand Down Expand Up @@ -305,7 +304,7 @@ def FromJsonString(self, value):
Raises:
ValueError: On parsing problems.
"""
if not isinstance(value, six.string_types):
if not isinstance(value, str):
raise ValueError('Duration JSON value not a string: {!r}'.format(value))
if len(value) < 1 or value[-1] != 's':
raise ValueError(
Expand Down Expand Up @@ -432,7 +431,7 @@ def ToJsonString(self):

def FromJsonString(self, value):
"""Converts string to FieldMask according to proto3 JSON spec."""
if not isinstance(value, six.string_types):
if not isinstance(value, str):
raise ValueError('FieldMask JSON value not a string: {!r}'.format(value))
self.Clear()
if value:
Expand Down Expand Up @@ -718,19 +717,16 @@ def _AddFieldPaths(node, prefix, field_mask):
_AddFieldPaths(node[name], child_path, field_mask)


_INT_OR_FLOAT = six.integer_types + (float,)


def _SetStructValue(struct_value, value):
if value is None:
struct_value.null_value = 0
elif isinstance(value, bool):
# Note: this check must come before the number check because in Python
# True and False are also considered numbers.
struct_value.bool_value = value
elif isinstance(value, six.string_types):
elif isinstance(value, str):
struct_value.string_value = value
elif isinstance(value, _INT_OR_FLOAT):
elif isinstance(value, (int, float)):
struct_value.number_value = value
elif isinstance(value, (dict, Struct)):
struct_value.struct_value.Clear()
Expand Down

0 comments on commit c70b4e5

Please sign in to comment.