Correct improper 'assert' statements
From:
__assert__ statements in Python are equivalent to:
* __if not expression1: raise AssertionError(expression2)__
So __assert type(string), unicode__ is equivalent to:
* __if not bool(type(string)): raise AssertionError(unicode)__
Also, Python best practice is to avoid directly comparing types but to use __isinstance()__ instead.
@@ -27,6 +27,11 @@ import termios
import app.config
+try:
+ unicode
+except NameError:
+ unicode = str
+
MIN_DOUBLE_WIDE_CHARACTER = u"\u3000"
# Strings are found using the cursesKeyName() function.
@@ -229,8 +234,8 @@ def columnToIndex(offset, string):
"""If the visual cursor is on |offset|, which index of the string is the
cursor on?"""
if app.config.strict_debug:
- assert type(offset), int
- assert type(string), unicode
+ assert isinstance(offset, int)
+ assert isinstance(string, unicode)
indexLimit = len(string) - 1
index = 0
for i in string:
@@ -249,8 +254,8 @@ def fitToRenderedWidth(width, string):
render?
"""
if app.config.strict_debug:
- assert type(width), int
- assert type(string), unicode
+ assert isinstance(width, int)
+ assert isinstance(string, unicode)
indexLimit = len(string)
index = 0
for i in string:
@@ -274,9 +279,9 @@ def renderedFindIter(string, beginCol, endCol, charGroups, numbers, eolSpaces):
tuple of (subStr, column, index, id)
"""
if app.config.strict_debug:
- assert type(string), unicode
- assert type(beginCol), int
- assert type(endCol), int
+ assert isinstance(string, unicode)
+ assert isinstance(beginCol, int)
+ assert isinstance(endCol, int)
column = 0
index = 0
limit = len(string)
@@ -327,9 +332,9 @@ def renderedSubStr(string, beginCol, endCol):
unicode string
"""
if app.config.strict_debug:
- assert type(string), unicode
- assert type(beginCol), int
- assert type(endCol), int
+ assert isinstance(string, unicode)
+ assert isinstance(beginCol, int)
+ assert isinstance(endCol, int)
column = 0
beginIndex = sys.maxsize
endIndex = sys.maxsize
@@ -382,7 +387,7 @@ def renderedWidth(string):
cells.
"""
if app.config.strict_debug:
- assert type(string), unicode
+ assert isinstance(string, unicode)
width = 0
for i in string:
if i > MIN_DOUBLE_WIDE_CHARACTER:
