Skip to content

Commit

Permalink
Remove six from console, eliminates six entirely (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbieber authored Sep 20, 2024
1 parent 4efd44d commit 93b0e32
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 39 deletions.
18 changes: 8 additions & 10 deletions fire/console/console_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@
from fire.console import encoding as encoding_util
from fire.console import text

import six


# TODO: Unify this logic with console.style.mappings
class BoxLineCharacters(object):
Expand Down Expand Up @@ -355,9 +353,9 @@ def ConvertOutputToUnicode(self, buf):
Returns:
The console output string buf converted to unicode.
"""
if isinstance(buf, six.text_type):
if isinstance(buf, str):
buf = buf.encode(self._encoding)
return six.text_type(buf, self._encoding, 'replace')
return str(buf, self._encoding, 'replace')

def GetBoxLineCharacters(self):
"""Returns the box/line drawing characters object.
Expand Down Expand Up @@ -480,7 +478,7 @@ def DisplayWidth(self, buf):
Returns:
The display width of buf, handling unicode and ANSI controls.
"""
if not isinstance(buf, six.string_types):
if not isinstance(buf, str):
# Handle non-string objects like Colorizer().
return len(buf)

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

def __eq__(self, other):
return self._string == six.text_type(other)
return self._string == str(other)

def __ne__(self, other):
return not self == other

def __gt__(self, other):
return self._string > six.text_type(other)
return self._string > str(other)

def __lt__(self, other):
return self._string < six.text_type(other)
return self._string < str(other)

def __ge__(self, other):
return not self < other
Expand Down Expand Up @@ -692,7 +690,7 @@ def GetCharacterDisplayWidth(char):
Returns:
The monospaced terminal display width of char: either 0, 1, or 2.
"""
if not isinstance(char, six.text_type):
if not isinstance(char, str):
# Non-unicode chars have width 1. Don't use this function on control chars.
return 1

Expand Down Expand Up @@ -779,7 +777,7 @@ def EncodeToBytes(data):
return data

# Coerce to text that will be converted to bytes.
s = six.text_type(data)
s = str(data)

try:
# Assume the text can be directly converted to bytes (8-bit ascii).
Expand Down
31 changes: 6 additions & 25 deletions fire/console/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import sys

import six


def Encode(string, encoding=None):
"""Encode the text string to a byte string.
Expand All @@ -35,18 +33,7 @@ def Encode(string, encoding=None):
Returns:
str, The binary string.
"""
if string is None:
return None
if not six.PY2:
# In Python 3, the environment sets and gets accept and return text strings
# only, and it handles the encoding itself so this is not necessary.
return string
if isinstance(string, six.binary_type):
# Already an encoded byte string, we are done
return string

encoding = encoding or _GetEncoding()
return string.encode(encoding)
return string


def Decode(data, encoding=None):
Expand All @@ -67,20 +54,13 @@ def Decode(data, encoding=None):
return None

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

if isinstance(string, six.text_type):
if isinstance(string, str):
# Our work is done here.
return string

Expand Down Expand Up @@ -199,7 +179,8 @@ def EncodeEnv(env, encoding=None):
encoding = encoding or _GetEncoding()
return {
Encode(k, encoding=encoding): Encode(v, encoding=encoding)
for k, v in six.iteritems(env)}
for k, v in env.items()
}


def _GetEncoding():
Expand Down
4 changes: 1 addition & 3 deletions fire/console/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from fire.console import encoding as encoding_util
from fire.console import platforms

import six


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

if isinstance(pathext, six.string_types):
if isinstance(pathext, str):
raise ValueError('_FindExecutableOnPath(..., pathext=\'{0}\') failed '
'because pathext must be an iterable of strings, but got '
'a string.'.format(pathext))
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
A library for automatically generating command line interfaces.""".strip()

DEPENDENCIES = [
'six',
'termcolor',
]

Expand Down

0 comments on commit 93b0e32

Please sign in to comment.