Skip to content

Commit 58ead8c

Browse files
authored
Merge pull request #191 from yilei/push_up_to_452372418
Push up to 452372418
2 parents ce06222 + 432398f commit 58ead8c

23 files changed

+46
-189
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com).
66

77
## Unreleased
88

9+
Nothing notable unreleased.
10+
11+
## 1.1.0 (2022-06-01)
12+
913
* `Flag` instances now raise an error if used in a bool context. This prevents
1014
the occasional mistake of testing an instance for truthiness rather than
1115
testing `flag.value`.
16+
* `absl-py` no longer depends on `six`.
1217

1318
## 1.0.0 (2021-11-09)
1419

WORKSPACE

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,3 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
workspace(name = "io_abseil_py")
15-
16-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
17-
18-
http_archive(
19-
name = "six_archive",
20-
build_file = "@//third_party:six.BUILD",
21-
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
22-
strip_prefix = "six-1.10.0",
23-
urls = [
24-
"http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
25-
"https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz",
26-
],
27-
)

absl/BUILD

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ py_library(
2121
visibility = ["//visibility:public"],
2222
)
2323

24-
py_library(
25-
name = "_collections_abc",
26-
srcs = ["_collections_abc.py"],
27-
visibility = [":__subpackages__"],
28-
deps = ["@six_archive//:six"],
29-
)
30-
3124
py_library(
3225
name = "tests/app_test_helper",
3326
testonly = 1,

absl/_collections_abc.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

absl/flags/BUILD

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ py_library(
1313
":_flagvalues",
1414
":_helpers",
1515
":_validators",
16-
"@six_archive//:six",
1716
],
1817
)
1918

@@ -31,7 +30,6 @@ py_library(
3130
srcs_version = "PY2AND3",
3231
deps = [
3332
":_helpers",
34-
"@six_archive//:six",
3533
],
3634
)
3735

@@ -66,8 +64,6 @@ py_library(
6664
":_argument_parser",
6765
":_exceptions",
6866
":_helpers",
69-
"//absl:_collections_abc",
70-
"@six_archive//:six",
7167
],
7268
)
7369

@@ -80,15 +76,13 @@ py_library(
8076
":_flag",
8177
":_helpers",
8278
":_validators_classes",
83-
"@six_archive//:six",
8479
],
8580
)
8681

8782
py_library(
8883
name = "_helpers",
8984
srcs = ["_helpers.py"],
9085
srcs_version = "PY2AND3",
91-
deps = ["@six_archive//:six"],
9286
)
9387

9488
py_library(

absl/flags/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
and optionally type-converted, when it's seen on the command line.
2626
"""
2727

28-
from __future__ import absolute_import
29-
from __future__ import division
30-
from __future__ import print_function
31-
3228
import getopt
3329
import os
3430
import re
@@ -43,7 +39,6 @@
4339
from absl.flags import _flagvalues
4440
from absl.flags import _helpers
4541
from absl.flags import _validators
46-
import six
4742

4843
# Initialize the FLAGS_MODULE as early as possible.
4944
# It's only used by adopt_module_key_flags to take SPECIAL_FLAGS into account.

absl/flags/_argument_parser.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
aliases defined at the package level instead.
1919
"""
2020

21-
from __future__ import absolute_import
22-
from __future__ import division
23-
from __future__ import print_function
24-
2521
import collections
2622
import csv
2723
import io
2824
import string
2925

3026
from absl.flags import _helpers
31-
import six
3227

3328

3429
def _is_integer_type(instance):
3530
"""Returns True if instance is an integer, and not a bool."""
36-
return (isinstance(instance, six.integer_types) and
31+
return (isinstance(instance, int) and
3732
not isinstance(instance, bool))
3833

3934

@@ -95,7 +90,7 @@ def __call__(cls, *args, **kwargs):
9590
# inherit from `ArgumentParser` and not `ArgumentParser[SomeType]`.
9691
# The corresponding DEFINE_someType method (the public API) can be annotated
9792
# to return FlagHolder[SomeType].
98-
class ArgumentParser(six.with_metaclass(_ArgumentParserCache, object)):
93+
class ArgumentParser(metaclass=_ArgumentParserCache):
9994
"""Base class used to parse and convert arguments.
10095
10196
The parse() method checks to make sure that the string argument is a
@@ -128,7 +123,7 @@ def parse(self, argument):
128123
Returns:
129124
The parsed value in native type.
130125
"""
131-
if not isinstance(argument, six.string_types):
126+
if not isinstance(argument, str):
132127
raise TypeError('flag value must be a string, found "{}"'.format(
133128
type(argument)))
134129
return argument
@@ -228,7 +223,7 @@ def __init__(self, lower_bound=None, upper_bound=None):
228223
def convert(self, argument):
229224
"""Returns the float value of argument."""
230225
if (_is_integer_type(argument) or isinstance(argument, float) or
231-
isinstance(argument, six.string_types)):
226+
isinstance(argument, str)):
232227
return float(argument)
233228
else:
234229
raise TypeError(
@@ -274,7 +269,7 @@ def convert(self, argument):
274269
"""Returns the int value of argument."""
275270
if _is_integer_type(argument):
276271
return argument
277-
elif isinstance(argument, six.string_types):
272+
elif isinstance(argument, str):
278273
base = 10
279274
if len(argument) > 2 and argument[0] == '0':
280275
if argument[1] == 'o':
@@ -296,14 +291,14 @@ class BooleanParser(ArgumentParser):
296291

297292
def parse(self, argument):
298293
"""See base class."""
299-
if isinstance(argument, six.string_types):
294+
if isinstance(argument, str):
300295
if argument.lower() in ('true', 't', '1'):
301296
return True
302297
elif argument.lower() in ('false', 'f', '0'):
303298
return False
304299
else:
305300
raise ValueError('Non-boolean argument to boolean flag', argument)
306-
elif isinstance(argument, six.integer_types):
301+
elif isinstance(argument, int):
307302
# Only allow bool or integer 0, 1.
308303
# Note that float 1.0 == True, 0.0 == False.
309304
bool_value = bool(argument)
@@ -433,7 +428,7 @@ def parse(self, argument):
433428
"""
434429
if isinstance(argument, self.enum_class):
435430
return argument
436-
elif not isinstance(argument, six.string_types):
431+
elif not isinstance(argument, str):
437432
raise ValueError(
438433
'{} is not an enum member or a name of a member in {}'.format(
439434
argument, self.enum_class))
@@ -496,18 +491,10 @@ def __init__(self, list_sep):
496491

497492
def serialize(self, value):
498493
"""Serializes a list as a CSV string or unicode."""
499-
if six.PY2:
500-
# In Python2 csv.writer doesn't accept unicode, so we convert to UTF-8.
501-
output = io.BytesIO()
502-
writer = csv.writer(output, delimiter=self.list_sep)
503-
writer.writerow([unicode(x).encode('utf-8') for x in value]) # pylint: disable=undefined-variable
504-
serialized_value = output.getvalue().decode('utf-8').strip()
505-
else:
506-
# In Python3 csv.writer expects a text stream.
507-
output = io.StringIO()
508-
writer = csv.writer(output, delimiter=self.list_sep)
509-
writer.writerow([str(x) for x in value])
510-
serialized_value = output.getvalue().strip()
494+
output = io.StringIO()
495+
writer = csv.writer(output, delimiter=self.list_sep)
496+
writer.writerow([str(x) for x in value])
497+
serialized_value = output.getvalue().strip()
511498

512499
# We need the returned value to be pure ascii or Unicodes so that
513500
# when the xml help is generated they are usefully encodable.

absl/flags/_flag.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@
1818
aliases defined at the package level instead.
1919
"""
2020

21-
from __future__ import absolute_import
22-
from __future__ import division
23-
from __future__ import print_function
24-
21+
from collections import abc
2522
import copy
2623
import functools
2724

28-
from absl._collections_abc import abc
2925
from absl.flags import _argument_parser
3026
from absl.flags import _exceptions
3127
from absl.flags import _helpers
32-
import six
3328

3429

3530
@functools.total_ordering
@@ -411,7 +406,7 @@ def parse(self, arguments):
411406

412407
def _parse(self, arguments):
413408
if (isinstance(arguments, abc.Iterable) and
414-
not isinstance(arguments, six.string_types)):
409+
not isinstance(arguments, str)):
415410
arguments = list(arguments)
416411

417412
if not isinstance(arguments, list):

absl/flags/_flag.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import copy
1818
import functools
1919

20-
from absl._collections_abc import abc
2120
from absl.flags import _argument_parser
2221
import enum
23-
import six
2422

2523
from typing import Text, TypeVar, Generic, Iterable, Type, List, Optional, Any, Union, Sequence
2624

0 commit comments

Comments
 (0)