diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-06-11 21:38:39 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-06-11 21:38:39 (GMT) |
commit | 5de48bdd195b14426c772b4c61290aef7f33e3ec (patch) | |
tree | e4411088f62f76b183b18d543b4c4b64d4076d65 /Lib/idlelib/PyParse.py | |
parent | 80bfb725af0809308264d526ac6a024fc8386643 (diff) | |
download | cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.zip cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.gz cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.bz2 |
Simplify various spots where: str() is called on something
that already is a string or the existence of the str class
is checked or a check is done for str twice. These all stem
from the initial unicode->str replacement.
Diffstat (limited to 'Lib/idlelib/PyParse.py')
-rw-r--r-- | Lib/idlelib/PyParse.py | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/Lib/idlelib/PyParse.py b/Lib/idlelib/PyParse.py index 463ad36..ea3cc27 100644 --- a/Lib/idlelib/PyParse.py +++ b/Lib/idlelib/PyParse.py @@ -104,33 +104,28 @@ for ch in "\"'\\\n#": _tran = ''.join(_tran) del ch -try: - UnicodeType = type(str("")) -except NameError: - UnicodeType = None - class Parser: def __init__(self, indentwidth, tabwidth): self.indentwidth = indentwidth self.tabwidth = tabwidth - def set_str(self, str): - assert len(str) == 0 or str[-1] == '\n' - if type(str) is UnicodeType: + def set_str(self, s): + assert len(s) == 0 or s[-1] == '\n' + if isinstance(s, str): # The parse functions have no idea what to do with Unicode, so # replace all Unicode characters with "x". This is "safe" # so long as the only characters germane to parsing the structure # of Python are 7-bit ASCII. It's *necessary* because Unicode # strings don't have a .translate() method that supports # deletechars. - uniphooey = str + uniphooey = s str = [] - push = str.append + push = s.append for raw in map(ord, uniphooey): push(raw < 127 and chr(raw) or "x") - str = "".join(str) - self.str = str + s = "".join(s) + self.str = s self.study_level = 0 # Return index of a good place to begin parsing, as close to the |