Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4cee82

Browse files
GlobalCompleter returns unicode matches
1 parentb230413 commitb4cee82

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

‎bpython/_py3compat.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ def prepare_for_exec(arg, encoding=None):
4949
else:
5050
defprepare_for_exec(arg,encoding=None):
5151
returnarg.encode(encoding)
52+
53+
54+
deftry_decode(s,encoding):
55+
"""Try to decode s which is str names. Return None if not decodable"""
56+
ifnotpy3andnotisinstance(s,unicode):
57+
try:
58+
returns.decode(encoding)
59+
exceptUnicodeDecodeError:
60+
returnNone
61+
returns

‎bpython/autocomplete.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
frombpythonimportinspection
3535
frombpythonimportimportcompletion
3636
frombpythonimportlineaslineparts
37-
frombpython._py3compatimportpy3
37+
frombpython._py3compatimportpy3,try_decode
3838
frombpython.lazyreimportLazyReCompile
3939

4040

@@ -286,11 +286,17 @@ def matches(self, cursor_offset, line, **kwargs):
286286
n=len(text)
287287
forwordinkeyword.kwlist:
288288
ifmethod_match(word,n,text):
289-
matches.add(word)
289+
word=try_decode(word,'ascii')# py2 keywords are all ascii
290+
ifwordisnotNone:
291+
matches.add(word)
290292
fornspacein [builtins.__dict__,locals_]:
291293
forword,valinnspace.items():
292294
if (method_match(word,len(text),text)and
293295
word!="__builtins__"):
296+
word=try_decode(word,'ascii')
297+
# if identifier isn't ascii, don't complete (syntax error)
298+
ifwordisNone:
299+
continue
294300
matches.add(_callable_postfix(val,word))
295301
returnmatches
296302

‎bpython/importcompletion.py‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23-
frombpython._py3compatimportpy3
23+
frombpython._py3compatimportpy3,try_decode
2424
frombpython.lineimportcurrent_word,current_import, \
2525
current_from_import_from,current_from_import_import
2626

@@ -42,17 +42,6 @@
4242
fully_loaded=False
4343

4444

45-
deftry_decode_module(module,encoding):
46-
"""Try to decode module names."""
47-
ifnotpy3andnotisinstance(module,unicode):
48-
try:
49-
returnmodule.decode(encoding)
50-
exceptUnicodeDecodeError:
51-
# Not importable anyway, ignore it
52-
returnNone
53-
returnmodule
54-
55-
5645
defmodule_matches(cw,prefix=''):
5746
"""Modules names to replace cw with"""
5847
full='%s.%s'% (prefix,cw)ifprefixelsecw
@@ -83,7 +72,7 @@ def attr_matches(cw, prefix='', only_modules=False):
8372
ifmodule_part:
8473
matches= ('%s.%s'% (module_part,m)forminmatches)
8574

86-
generator= (try_decode_module(match,'ascii')formatchinmatches)
75+
generator= (try_decode(match,'ascii')formatchinmatches)
8776
returnset(filter(lambdax:xisnotNone,generator))
8877

8978

@@ -184,7 +173,7 @@ def find_all_modules(path=None):
184173
ifnotp:
185174
p=os.curdir
186175
formoduleinfind_modules(p):
187-
module=try_decode_module(module,sys.getfilesystemencoding())
176+
module=try_decode(module,sys.getfilesystemencoding())
188177
ifmoduleisNone:
189178
continue
190179
modules.add(module)

‎bpython/test/test_autocomplete.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: utf-8
2+
13
fromcollectionsimportnamedtuple
24
importinspect
35
frombpython._py3compatimportpy3
@@ -273,6 +275,15 @@ def function():
273275
locals_={'function':function}),
274276
set(('function(', )))
275277

278+
deftest_completions_are_unicode(self):
279+
forminself.com.matches(1,'a',locals_={'abc':10}):
280+
self.assertIsInstance(m,type(u''))
281+
282+
@unittest.skipIf(py3,"in Python 3 invalid identifiers are passed through")
283+
deftest_ignores_nonascii_encodable(self):
284+
self.assertSetEqual(self.com.matches(1,'abc',locals_={'abcß':10}),
285+
set())
286+
276287

277288
classTestParameterNameCompletion(unittest.TestCase):
278289
deftest_set_of_params_returns_when_matches_found(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp