mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Update the code to better reflect recommended style:
Use != instead of <> since <> is documented as "obsolescent". Use "is" and "is not" when comparing with None or type objects.
This commit is contained in:
parent
63596aeb33
commit
132dce2246
55 changed files with 520 additions and 519 deletions
|
@ -28,7 +28,7 @@ class Para:
|
|||
# Each word should be a 7-tuple:
|
||||
# (font, text, width, space, stretch, ascent, descent)
|
||||
def addword(self, d, font, text, space, stretch):
|
||||
if font <> None:
|
||||
if font is not None:
|
||||
d.setfont(font)
|
||||
width = d.textwidth(text)
|
||||
ascent = d.baseline()
|
||||
|
@ -50,7 +50,7 @@ class Para:
|
|||
def getlength(self):
|
||||
total = 0
|
||||
for word in self.words:
|
||||
if type(word) <> Int:
|
||||
if type(word) is not Int:
|
||||
total = total + word[2] + word[3]
|
||||
return total
|
||||
#
|
||||
|
@ -63,7 +63,7 @@ class Para:
|
|||
as, de = 1, 0
|
||||
for i in range(len(self.words)):
|
||||
word = self.words[i]
|
||||
if type(word) == Int: continue
|
||||
if type(word) is Int: continue
|
||||
(fo, te, wi, sp, st, as, de) = word
|
||||
self.words[i] = (fo, te, wi, sp, 0, as, de)
|
||||
total = total + wi + sp
|
||||
|
@ -99,7 +99,7 @@ class Para:
|
|||
j = i
|
||||
while i < n:
|
||||
word = words[i]
|
||||
if type(word) == Int:
|
||||
if type(word) is Int:
|
||||
if word > 0 and width >= avail:
|
||||
break
|
||||
i = i+1
|
||||
|
@ -107,7 +107,7 @@ class Para:
|
|||
fo, te, wi, sp, st, as, de = word
|
||||
if width + wi > avail and width > 0 and wi > 0:
|
||||
break
|
||||
if fo <> None:
|
||||
if fo is not None:
|
||||
lastfont = fo
|
||||
if width == 0:
|
||||
firstfont = fo
|
||||
|
@ -119,7 +119,7 @@ class Para:
|
|||
ascent = max(ascent, as)
|
||||
descent = max(descent, de)
|
||||
i = i+1
|
||||
while i > j and type(words[i-1]) == Int and \
|
||||
while i > j and type(words[i-1]) is Int and \
|
||||
words[i-1] > 0: i = i-1
|
||||
width = width - lsp
|
||||
if i < n:
|
||||
|
@ -152,10 +152,10 @@ class Para:
|
|||
v2 = v + ascent + descent
|
||||
for j in range(i, i+wordcount):
|
||||
word = self.words[j]
|
||||
if type(word) == Int:
|
||||
if type(word) is Int:
|
||||
ok = anchorfunc(self, tuple, word, \
|
||||
h, v)
|
||||
if ok <> None: return ok
|
||||
if ok is not None: return ok
|
||||
continue
|
||||
fo, te, wi, sp, st, as, de = word
|
||||
if extra > 0 and stretch > 0:
|
||||
|
@ -167,7 +167,7 @@ class Para:
|
|||
h2 = h + wi + sp + ex
|
||||
ok = wordfunc(self, tuple, word, h, v, \
|
||||
h2, v2, (j==i), (j==i+wordcount-1))
|
||||
if ok <> None: return ok
|
||||
if ok is not None: return ok
|
||||
h = h2
|
||||
v = v2
|
||||
i = i + wordcount
|
||||
|
@ -177,7 +177,7 @@ class Para:
|
|||
# given by (left, top, right) with an unspecified bottom.
|
||||
# Return the computed bottom of the text.
|
||||
def render(self, d, left, top, right):
|
||||
if self.width <> right-left:
|
||||
if self.width != right-left:
|
||||
self.layout(right-left)
|
||||
self.left = left
|
||||
self.top = top
|
||||
|
@ -193,7 +193,7 @@ class Para:
|
|||
return self.bottom
|
||||
#
|
||||
def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
|
||||
if word[0] <> None: self.d.setfont(word[0])
|
||||
if word[0] is not None: self.d.setfont(word[0])
|
||||
baseline = v + tuple[5]
|
||||
self.d.text((h, baseline - word[5]), word[1])
|
||||
if self.anchorid > 0:
|
||||
|
@ -229,7 +229,7 @@ class Para:
|
|||
def extract(self):
|
||||
text = ''
|
||||
for w in self.words:
|
||||
if type(w) <> Int:
|
||||
if type(w) is not Int:
|
||||
word = w[1]
|
||||
if w[3]: word = word + ' '
|
||||
text = text + word
|
||||
|
@ -254,14 +254,14 @@ class Para:
|
|||
#
|
||||
def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
||||
fo, te, wi, sp, st, as, de = word
|
||||
if fo <> None: self.lastfont = fo
|
||||
if fo is not None: self.lastfont = fo
|
||||
h = h1
|
||||
if isfirst: h1 = 0
|
||||
if islast: h2 = 999999
|
||||
if not (v1 <= self.mousev <= v2 and h1 <= self.mouseh <= h2):
|
||||
self.charcount = self.charcount + len(te) + (sp > 0)
|
||||
return
|
||||
if self.lastfont <> None:
|
||||
if self.lastfont is not None:
|
||||
self.d.setfont(self.lastfont)
|
||||
cc = 0
|
||||
for c in te:
|
||||
|
@ -295,7 +295,7 @@ class Para:
|
|||
self.__class__._screenposanchor)
|
||||
finally:
|
||||
self.d = None
|
||||
if ok == None:
|
||||
if ok is None:
|
||||
ascent, descent = self.lines[-1][5:7]
|
||||
ok = self.right, self.bottom - ascent - descent, \
|
||||
self.bottom - descent, self.bottom
|
||||
|
@ -303,7 +303,7 @@ class Para:
|
|||
#
|
||||
def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
||||
fo, te, wi, sp, st, as, de = word
|
||||
if fo <> None: self.lastfont = fo
|
||||
if fo is not None: self.lastfont = fo
|
||||
cc = len(te) + (sp > 0)
|
||||
if self.pos > cc:
|
||||
self.pos = self.pos - cc
|
||||
|
@ -324,11 +324,11 @@ class Para:
|
|||
# if pos2 is None, the end is implied.
|
||||
# Undoes its own effect when called again with the same arguments
|
||||
def invert(self, d, pos1, pos2):
|
||||
if pos1 == None:
|
||||
if pos1 is None:
|
||||
pos1 = self.left, self.top, self.top, self.top
|
||||
else:
|
||||
pos1 = self.screenpos(d, pos1)
|
||||
if pos2 == None:
|
||||
if pos2 is None:
|
||||
pos2 = self.right, self.bottom,self.bottom,self.bottom
|
||||
else:
|
||||
pos2 = self.screenpos(d, pos2)
|
||||
|
|
|
@ -16,13 +16,13 @@ def cmp(f1, f2, shallow=1):
|
|||
Return 1 for identical files, 0 for different.
|
||||
Raise exceptions if either file could not be statted, read, etc."""
|
||||
s1, s2 = sig(os.stat(f1)), sig(os.stat(f2))
|
||||
if s1[0] <> 8 or s2[0] <> 8:
|
||||
if s1[0] != 8 or s2[0] != 8:
|
||||
# Either is a not a plain file -- always report as different
|
||||
return 0
|
||||
if shallow and s1 == s2:
|
||||
# type, size & mtime match -- report same
|
||||
return 1
|
||||
if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother
|
||||
if s1[:2] != s2[:2]: # Types or sizes differ, don't bother
|
||||
# types or sizes differ -- report different
|
||||
return 0
|
||||
# same type and size -- look in the cache
|
||||
|
@ -59,5 +59,5 @@ def do_cmp(f1, f2):
|
|||
while 1:
|
||||
b1 = fp1.read(bufsize)
|
||||
b2 = fp2.read(bufsize)
|
||||
if b1 <> b2: return 0
|
||||
if b1 != b2: return 0
|
||||
if not b1: return 1
|
||||
|
|
|
@ -30,7 +30,7 @@ def cmp(f1, f2, shallow=1):
|
|||
if shallow and s1 == s2:
|
||||
# type, size & mtime match -- report same
|
||||
return 1
|
||||
if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother
|
||||
if s1[:2] != s2[:2]: # Types or sizes differ, don't bother
|
||||
# types or sizes differ -- report different
|
||||
return 0
|
||||
# same type and size -- look in the cache
|
||||
|
@ -60,5 +60,5 @@ def do_cmp(f1, f2):
|
|||
while 1:
|
||||
b1 = fp1.read(bufsize)
|
||||
b2 = fp2.read(bufsize)
|
||||
if b1 <> b2: return 0
|
||||
if b1 != b2: return 0
|
||||
if not b1: return 1
|
||||
|
|
|
@ -70,7 +70,7 @@ class dircmp:
|
|||
if ok:
|
||||
a_type = S_IFMT(a_stat[ST_MODE])
|
||||
b_type = S_IFMT(b_stat[ST_MODE])
|
||||
if a_type <> b_type:
|
||||
if a_type != b_type:
|
||||
self.common_funny.append(x)
|
||||
elif S_ISDIR(a_type):
|
||||
self.common_dirs.append(x)
|
||||
|
@ -189,7 +189,8 @@ def demo():
|
|||
import sys
|
||||
import getopt
|
||||
options, args = getopt.getopt(sys.argv[1:], 'r')
|
||||
if len(args) <> 2: raise getopt.error, 'need exactly two args'
|
||||
if len(args) != 2:
|
||||
raise getopt.error, 'need exactly two args'
|
||||
dd = dircmp().new(args[0], args[1])
|
||||
dd.run()
|
||||
if ('-r', '') in options:
|
||||
|
|
|
@ -68,20 +68,20 @@ class SavingBackEnd(NullBackEnd):
|
|||
for i in range(len(self.paralist)):
|
||||
p = self.paralist[i]
|
||||
result = p.whereis(d, h, v)
|
||||
if result <> None:
|
||||
if result is not None:
|
||||
return i, result
|
||||
return None
|
||||
#
|
||||
def roundtowords(self, long1, long2):
|
||||
i, offset = long1
|
||||
text = self.paralist[i].extract()
|
||||
while offset > 0 and text[offset-1] <> ' ': offset = offset-1
|
||||
while offset > 0 and text[offset-1] != ' ': offset = offset-1
|
||||
long1 = i, offset
|
||||
#
|
||||
i, offset = long2
|
||||
text = self.paralist[i].extract()
|
||||
n = len(text)
|
||||
while offset < n-1 and text[offset] <> ' ': offset = offset+1
|
||||
while offset < n-1 and text[offset] != ' ': offset = offset+1
|
||||
long2 = i, offset
|
||||
#
|
||||
return long1, long2
|
||||
|
@ -159,7 +159,7 @@ class BaseFormatter:
|
|||
return Para.Para()
|
||||
#
|
||||
def setfont(self, font):
|
||||
if font == None: return
|
||||
if font is None: return
|
||||
self.font = self.nextfont = font
|
||||
d = self.d
|
||||
d.setfont(font)
|
||||
|
@ -193,7 +193,7 @@ class BaseFormatter:
|
|||
if self.para:
|
||||
self.b.addpara(self.para)
|
||||
self.para = None
|
||||
if self.font <> None:
|
||||
if self.font is not None:
|
||||
self.d.setfont(self.font)
|
||||
self.nospace = 1
|
||||
#
|
||||
|
@ -338,8 +338,8 @@ def finalize(para):
|
|||
para.words.append(('r', '', 0, 0, 0, 0)) # temporary, deleted at end
|
||||
for i in range(len(para.words)):
|
||||
fo, te, wi = para.words[i][:3]
|
||||
if fo <> None: curfont = fo
|
||||
if curfont <> oldfont:
|
||||
if fo is not None: curfont = fo
|
||||
if curfont != oldfont:
|
||||
if closechar.has_key(oldfont):
|
||||
c = closechar[oldfont]
|
||||
j = i-1
|
||||
|
@ -430,7 +430,7 @@ class StdwinBackEnd(SavingBackEnd):
|
|||
pos1 = long1[:3]
|
||||
pos2 = long2[:3]
|
||||
new = pos1, pos2
|
||||
if new <> self.selection:
|
||||
if new != self.selection:
|
||||
d = self.window.begindrawing()
|
||||
if self.selection:
|
||||
self.invert(d, self.selection)
|
||||
|
@ -462,7 +462,7 @@ class StdwinBackEnd(SavingBackEnd):
|
|||
#
|
||||
def search(self, prog):
|
||||
import re, string
|
||||
if type(prog) == type(''):
|
||||
if type(prog) is type(''):
|
||||
prog = re.compile(string.lower(prog))
|
||||
if self.selection:
|
||||
iold = self.selection[0][0]
|
||||
|
@ -551,7 +551,7 @@ class GLFontCache:
|
|||
self.fontcache[fontkey] = \
|
||||
self.fontcache[key] = handle
|
||||
self.fontkey = fontkey
|
||||
if self.fonthandle <> handle:
|
||||
if self.fonthandle != handle:
|
||||
self.fonthandle = handle
|
||||
self.fontinfo = handle.getfontinfo()
|
||||
handle.setfont()
|
||||
|
@ -582,7 +582,7 @@ class GLWriter(GLFontCache):
|
|||
def setfont(self, fontkey):
|
||||
oldhandle = self.fonthandle
|
||||
GLFontCache.setfont(fontkey)
|
||||
if self.fonthandle <> oldhandle:
|
||||
if self.fonthandle != oldhandle:
|
||||
handle.setfont()
|
||||
|
||||
|
||||
|
@ -612,7 +612,7 @@ class GLBackEnd(SavingBackEnd):
|
|||
import gl
|
||||
gl.winset(self.wid)
|
||||
width = gl.getsize()[1]
|
||||
if width <> self.width:
|
||||
if width != self.width:
|
||||
setdocsize = 1
|
||||
self.width = width
|
||||
for p in self.paralist:
|
||||
|
|
|
@ -73,7 +73,7 @@ def showline(filename, lineno, line, prog):
|
|||
else:
|
||||
prefix = ' ' * len(prefix)
|
||||
for c in line:
|
||||
if c <> '\t': c = ' '
|
||||
if c != '\t': c = ' '
|
||||
prefix = prefix + c
|
||||
if start == end: prefix = prefix + '\\'
|
||||
else: prefix = prefix + '^'*(end-start)
|
||||
|
|
|
@ -25,7 +25,7 @@ def pack(outfp, file, name):
|
|||
while 1:
|
||||
line = fp.readline()
|
||||
if not line: break
|
||||
if line[-1:] <> '\n':
|
||||
if line[-1:] != '\n':
|
||||
line = line + '\n'
|
||||
outfp.write('X' + line)
|
||||
outfp.write('!\n')
|
||||
|
|
|
@ -23,7 +23,7 @@ def browser(tb):
|
|||
ptr = len(tblist)-1
|
||||
tb = tblist[ptr]
|
||||
while 1:
|
||||
if tb <> tblist[ptr]:
|
||||
if tb != tblist[ptr]:
|
||||
tb = tblist[ptr]
|
||||
print `ptr` + ':',
|
||||
printtbheader(tb)
|
||||
|
@ -76,11 +76,11 @@ def browserexec(tb, cmd):
|
|||
except:
|
||||
t, v = sys.exc_info()[:2]
|
||||
print '*** Exception:',
|
||||
if type(t) == type(''):
|
||||
if type(t) is type(''):
|
||||
print t,
|
||||
else:
|
||||
print t.__name__,
|
||||
if v <> None:
|
||||
if v is not None:
|
||||
print ':', v,
|
||||
print
|
||||
print 'Type help to get help.'
|
||||
|
@ -127,24 +127,24 @@ def printsymbols(d):
|
|||
print
|
||||
|
||||
def printobject(v, maxlevel):
|
||||
if v == None:
|
||||
if v is None:
|
||||
print 'None',
|
||||
elif type(v) in (type(0), type(0.0)):
|
||||
print v,
|
||||
elif type(v) == type(''):
|
||||
elif type(v) is type(''):
|
||||
if len(v) > 20:
|
||||
print `v[:17] + '...'`,
|
||||
else:
|
||||
print `v`,
|
||||
elif type(v) == type(()):
|
||||
elif type(v) is type(()):
|
||||
print '(',
|
||||
printlist(v, maxlevel)
|
||||
print ')',
|
||||
elif type(v) == type([]):
|
||||
elif type(v) is type([]):
|
||||
print '[',
|
||||
printlist(v, maxlevel)
|
||||
print ']',
|
||||
elif type(v) == type({}):
|
||||
elif type(v) is type({}):
|
||||
print '{',
|
||||
printdict(v, maxlevel)
|
||||
print '}',
|
||||
|
|
|
@ -82,13 +82,13 @@ def checkfield(n, p):
|
|||
print inv
|
||||
|
||||
def rj(s, width):
|
||||
if type(s) <> type(''): s = `s`
|
||||
if type(s) is not type(''): s = `s`
|
||||
n = len(s)
|
||||
if n >= width: return s
|
||||
return ' '*(width - n) + s
|
||||
|
||||
def lj(s, width):
|
||||
if type(s) <> type(''): s = `s`
|
||||
if type(s) is not type(''): s = `s`
|
||||
n = len(s)
|
||||
if n >= width: return s
|
||||
return s + ' '*(width - n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue