Skip to content

Commit 93b0e32

Browse files
authored
Remove six from console, eliminates six entirely (#552)
1 parent 4efd44d commit 93b0e32

4 files changed

Lines changed: 15 additions & 39 deletions

File tree

fire/console/console_attr.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
from fire.console import encoding as encoding_util
101101
from fire.console import text
102102

103-
import six
104-
105103

106104
# TODO: Unify this logic with console.style.mappings
107105
class BoxLineCharacters(object):
@@ -355,9 +353,9 @@ def ConvertOutputToUnicode(self, buf):
355353
Returns:
356354
The console output string buf converted to unicode.
357355
"""
358-
if isinstance(buf, six.text_type):
356+
if isinstance(buf, str):
359357
buf = buf.encode(self._encoding)
360-
return six.text_type(buf, self._encoding, 'replace')
358+
return str(buf, self._encoding, 'replace')
361359

362360
def GetBoxLineCharacters(self):
363361
"""Returns the box/line drawing characters object.
@@ -480,7 +478,7 @@ def DisplayWidth(self, buf):
480478
Returns:
481479
The display width of buf, handling unicode and ANSI controls.
482480
"""
483-
if not isinstance(buf, six.string_types):
481+
if not isinstance(buf, str):
484482
# Handle non-string objects like Colorizer().
485483
return len(buf)
486484

@@ -595,16 +593,16 @@ def __init__(self, string, color, justify=None):
595593
self._justify = justify
596594

597595
def __eq__(self, other):
598-
return self._string == six.text_type(other)
596+
return self._string == str(other)
599597

600598
def __ne__(self, other):
601599
return not self == other
602600

603601
def __gt__(self, other):
604-
return self._string > six.text_type(other)
602+
return self._string > str(other)
605603

606604
def __lt__(self, other):
607-
return self._string < six.text_type(other)
605+
return self._string < str(other)
608606

609607
def __ge__(self, other):
610608
return not self < other
@@ -692,7 +690,7 @@ def GetCharacterDisplayWidth(char):
692690
Returns:
693691
The monospaced terminal display width of char: either 0, 1, or 2.
694692
"""
695-
if not isinstance(char, six.text_type):
693+
if not isinstance(char, str):
696694
# Non-unicode chars have width 1. Don't use this function on control chars.
697695
return 1
698696

@@ -779,7 +777,7 @@ def EncodeToBytes(data):
779777
return data
780778

781779
# Coerce to text that will be converted to bytes.
782-
s = six.text_type(data)
780+
s = str(data)
783781

784782
try:
785783
# Assume the text can be directly converted to bytes (8-bit ascii).

fire/console/encoding.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import sys
2424

25-
import six
26-
2725

2826
def Encode(string, encoding=None):
2927
"""Encode the text string to a byte string.
@@ -35,18 +33,7 @@ def Encode(string, encoding=None):
3533
Returns:
3634
str, The binary string.
3735
"""
38-
if string is None:
39-
return None
40-
if not six.PY2:
41-
# In Python 3, the environment sets and gets accept and return text strings
42-
# only, and it handles the encoding itself so this is not necessary.
43-
return string
44-
if isinstance(string, six.binary_type):
45-
# Already an encoded byte string, we are done
46-
return string
47-
48-
encoding = encoding or _GetEncoding()
49-
return string.encode(encoding)
36+
return string
5037

5138

5239
def Decode(data, encoding=None):
@@ -67,20 +54,13 @@ def Decode(data, encoding=None):
6754
return None
6855

6956
# First we are going to get the data object to be a text string.
70-
# Don't use six.string_types here because on Python 3 bytes is not considered
71-
# a string type and we want to include that.
72-
if isinstance(data, six.text_type) or isinstance(data, six.binary_type):
57+
if isinstance(data, str) or isinstance(data, bytes):
7358
string = data
7459
else:
7560
# Some non-string type of object.
76-
try:
77-
string = six.text_type(data)
78-
except (TypeError, UnicodeError):
79-
# The string cannot be converted to unicode -- default to str() which will
80-
# catch objects with special __str__ methods.
81-
string = str(data)
61+
string = str(data)
8262

83-
if isinstance(string, six.text_type):
63+
if isinstance(string, str):
8464
# Our work is done here.
8565
return string
8666

@@ -199,7 +179,8 @@ def EncodeEnv(env, encoding=None):
199179
encoding = encoding or _GetEncoding()
200180
return {
201181
Encode(k, encoding=encoding): Encode(v, encoding=encoding)
202-
for k, v in six.iteritems(env)}
182+
for k, v in env.items()
183+
}
203184

204185

205186
def _GetEncoding():

fire/console/files.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from fire.console import encoding as encoding_util
2525
from fire.console import platforms
2626

27-
import six
28-
2927

3028
def _GetSystemPath():
3129
"""Returns properly encoded system PATH variable string."""
@@ -48,7 +46,7 @@ def _FindExecutableOnPath(executable, path, pathext):
4846
ValueError: invalid input.
4947
"""
5048

51-
if isinstance(pathext, six.string_types):
49+
if isinstance(pathext, str):
5250
raise ValueError('_FindExecutableOnPath(..., pathext=\'{0}\') failed '
5351
'because pathext must be an iterable of strings, but got '
5452
'a string.'.format(pathext))

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
A library for automatically generating command line interfaces.""".strip()
3030

3131
DEPENDENCIES = [
32-
'six',
3332
'termcolor',
3433
]
3534

0 commit comments

Comments
 (0)