Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
11bb1ad1
Commit
11bb1ad1
authored
Nov 24, 2015
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25663: Merge rlcompleter fix from 3.4 into 3.5
parents
1f847659
ed929108
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
Lib/rlcompleter.py
Lib/rlcompleter.py
+5
-2
Lib/test/test_rlcompleter.py
Lib/test/test_rlcompleter.py
+21
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/rlcompleter.py
View file @
11bb1ad1
...
...
@@ -103,13 +103,16 @@ class Completer:
"""
import
keyword
matches
=
[]
seen
=
{
"__builtins__"
}
n
=
len
(
text
)
for
word
in
keyword
.
kwlist
:
if
word
[:
n
]
==
text
:
seen
.
add
(
word
)
matches
.
append
(
word
)
for
nspace
in
[
builtins
.
__dict__
,
self
.
namespace
]:
for
nspace
in
[
self
.
namespace
,
builtins
.
__dict__
]:
for
word
,
val
in
nspace
.
items
():
if
word
[:
n
]
==
text
and
word
!=
"__builtins__"
:
if
word
[:
n
]
==
text
and
word
not
in
seen
:
seen
.
add
(
word
)
matches
.
append
(
self
.
_callable_postfix
(
val
,
word
))
return
matches
...
...
Lib/test/test_rlcompleter.py
View file @
11bb1ad1
...
...
@@ -85,5 +85,26 @@ class TestRlcompleter(unittest.TestCase):
self
.
assertEqual
(
completer
.
complete
(
'as'
,
2
),
'assert'
)
self
.
assertEqual
(
completer
.
complete
(
'an'
,
0
),
'and'
)
def
test_duplicate_globals
(
self
):
namespace
=
{
'False'
:
None
,
# Keyword vs builtin vs namespace
'assert'
:
None
,
# Keyword vs namespace
'try'
:
lambda
:
None
,
# Keyword vs callable
'memoryview'
:
None
,
# Callable builtin vs non-callable
'Ellipsis'
:
lambda
:
None
,
# Non-callable builtin vs callable
}
completer
=
rlcompleter
.
Completer
(
namespace
)
self
.
assertEqual
(
completer
.
complete
(
'False'
,
0
),
'False'
)
self
.
assertIsNone
(
completer
.
complete
(
'False'
,
1
))
# No duplicates
self
.
assertEqual
(
completer
.
complete
(
'assert'
,
0
),
'assert'
)
self
.
assertIsNone
(
completer
.
complete
(
'assert'
,
1
))
self
.
assertEqual
(
completer
.
complete
(
'try'
,
0
),
'try'
)
self
.
assertIsNone
(
completer
.
complete
(
'try'
,
1
))
# No opening bracket "(" because we overrode the built-in class
self
.
assertEqual
(
completer
.
complete
(
'memoryview'
,
0
),
'memoryview'
)
self
.
assertIsNone
(
completer
.
complete
(
'memoryview'
,
1
))
self
.
assertEqual
(
completer
.
complete
(
'Ellipsis'
,
0
),
'Ellipsis('
)
self
.
assertIsNone
(
completer
.
complete
(
'Ellipsis'
,
1
))
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
11bb1ad1
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #25663: In the Readline completer, avoid listing duplicate global
names, and search the global namespace before searching builtins.
- Issue #25688: Fixed file leak in ElementTree.iterparse() raising an error.
- Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment