Skip to content

Commit 1ef1776

Browse files
committed
Remove bpython._py3compat.try_decode
1 parent d4ce21e commit 1ef1776

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

bpython/_py3compat.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,3 @@
3434
import sys
3535

3636
py3 = sys.version_info[0] == 3
37-
38-
39-
if py3:
40-
41-
def try_decode(s, encoding):
42-
return s
43-
44-
45-
else:
46-
47-
def try_decode(s, encoding):
48-
"""Try to decode s which is str names. Return None if not decodable"""
49-
if not isinstance(s, unicode):
50-
try:
51-
return s.decode(encoding)
52-
except UnicodeDecodeError:
53-
return None
54-
return s

bpython/autocomplete.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from . import importcompletion
3838
from . import line as lineparts
3939
from .line import LinePart
40-
from ._py3compat import py3, try_decode
40+
from ._py3compat import py3
4141
from .lazyre import LazyReCompile
4242
from .simpleeval import safe_eval, evaluate_current_expression, EvaluationError
4343

@@ -470,7 +470,6 @@ def matches(self, cursor_offset, line, **kwargs):
470470
matches.add(word)
471471
for nspace in (builtins.__dict__, locals_):
472472
for word, val in iteritems(nspace):
473-
word = try_decode(word, "ascii")
474473
# if identifier isn't ascii, don't complete (syntax error)
475474
if word is None:
476475
continue
@@ -580,7 +579,7 @@ def matches(self, cursor_offset, line, **kwargs):
580579

581580
first_letter = line[self._orig_start : self._orig_start + 1]
582581

583-
matches = [try_decode(c.name, "ascii") for c in completions]
582+
matches = [c.name for c in completions]
584583
if any(
585584
not m.lower().startswith(matches[0][0].lower()) for m in matches
586585
):

bpython/importcompletion.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# THE SOFTWARE.
2222

2323

24-
from ._py3compat import py3, try_decode
24+
from ._py3compat import py3
2525
from .line import (
2626
current_word,
2727
current_import,
@@ -76,22 +76,21 @@ def attr_matches(cw, prefix="", only_modules=False):
7676
return set()
7777
module = sys.modules[module_name]
7878
if only_modules:
79-
matches = (
79+
matches = {
8080
name
8181
for name in dir(module)
8282
if name.startswith(name_after_dot)
8383
and "%s.%s" % (module_name, name) in sys.modules
84-
)
84+
}
8585
else:
86-
matches = (
86+
matches = {
8787
name for name in dir(module) if name.startswith(name_after_dot)
88-
)
88+
}
8989
module_part, _, _ = cw.rpartition(".")
9090
if module_part:
91-
matches = ("%s.%s" % (module_part, m) for m in matches)
91+
matches = {"%s.%s" % (module_part, m) for m in matches}
9292

93-
generator = (try_decode(match, "ascii") for match in matches)
94-
return set(filter(lambda x: x is not None, generator))
93+
return matches
9594

9695

9796
def module_attr_matches(name):
@@ -210,16 +209,13 @@ def find_all_modules(path=None):
210209
"""Return a list with all modules in `path`, which should be a list of
211210
directory names. If path is not given, sys.path will be used."""
212211
if path is None:
213-
modules.update(try_decode(m, "ascii") for m in sys.builtin_module_names)
212+
modules.update(sys.builtin_module_names)
214213
path = sys.path
215214

216215
for p in path:
217216
if not p:
218217
p = os.curdir
219218
for module in find_modules(p):
220-
module = try_decode(module, "ascii")
221-
if module is None:
222-
continue
223219
modules.add(module)
224220
yield
225221

0 commit comments

Comments
 (0)