X Tutup
Skip to content

Commit ec79bd8

Browse files
committed
Remove global state of bpython.importcompletion
Repls now have a ModuleGartherer instance that performs the job.
1 parent 400d7e2 commit ec79bd8

File tree

9 files changed

+225
-225
lines changed

9 files changed

+225
-225
lines changed

bpython/autocomplete.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The MIT License
22
#
33
# Copyright (c) 2009-2015 the bpython authors.
4+
# Copyright (c) 2015-2020 Sebastian Ramacher
45
#
56
# Permission is hereby granted, free of charge, to any person obtaining a copy
67
# of this software and associated documentation files (the "Software"), to deal
@@ -34,7 +35,6 @@
3435

3536
from enum import Enum
3637
from . import inspection
37-
from . import importcompletion
3838
from . import line as lineparts
3939
from .line import LinePart
4040
from .lazyre import LazyReCompile
@@ -285,8 +285,12 @@ def matches(self, cursor_offset, line, **kwargs):
285285

286286

287287
class ImportCompletion(BaseCompletionType):
288+
def __init__(self, module_gatherer, mode=AutocompleteModes.SIMPLE):
289+
super().__init__(False, mode)
290+
self.module_gatherer = module_gatherer
291+
288292
def matches(self, cursor_offset, line, **kwargs):
289-
return importcompletion.complete(cursor_offset, line)
293+
return self.module_gatherer.complete(cursor_offset, line)
290294

291295
def locate(self, current_offset, line):
292296
return lineparts.current_word(current_offset, line)
@@ -656,10 +660,10 @@ def get_completer(completers, cursor_offset, line, **kwargs):
656660
return [], None
657661

658662

659-
def get_default_completer(mode=AutocompleteModes.SIMPLE):
663+
def get_default_completer(mode=AutocompleteModes.SIMPLE, module_gatherer=None):
660664
return (
661665
DictKeyCompletion(mode=mode),
662-
ImportCompletion(mode=mode),
666+
ImportCompletion(module_gatherer, mode=mode),
663667
FilenameCompletion(mode=mode),
664668
MagicMethodCompletion(mode=mode),
665669
MultilineJediCompletion(mode=mode),

bpython/cli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
from pygments.token import Token
6767
from .formatter import BPythonFormatter
6868

69-
# This for completion
70-
from . import importcompletion
71-
7269
# This for config
7370
from .config import Struct, getpreferredencoding
7471

@@ -1784,7 +1781,7 @@ def idle(caller):
17841781
sure it happens conveniently."""
17851782
global DO_RESIZE
17861783

1787-
if importcompletion.find_coroutine() or caller.paste_mode:
1784+
if caller.module_gatherer.find_coroutine() or caller.paste_mode:
17881785
caller.scr.nodelay(True)
17891786
key = caller.scr.getch()
17901787
caller.scr.nodelay(False)

bpython/curtsies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from . import args as bpargs
1414
from . import translations
1515
from .translations import _
16-
from .importcompletion import find_coroutine
1716
from .curtsiesfrontend import events as bpythonevents
1817
from . import inspection
1918
from .repl import extract_exit_value
@@ -113,7 +112,7 @@ def mainloop(self, interactive=True, paste=None):
113112
# do a display before waiting for first event
114113
self.process_event_and_paint(None)
115114
inputs = combined_events(self.input_generator)
116-
while find_coroutine():
115+
while self.module_gatherer.find_coroutine():
117116
e = inputs.send(0)
118117
if e is not None:
119118
self.process_event_and_paint(e)

0 commit comments

Comments
 (0)
X Tutup