1818aliases 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-
2521import collections
2622import csv
2723import io
2824import string
2925
3026from absl .flags import _helpers
31- import six
3227
3328
3429def _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.
0 commit comments