@@ -56,11 +56,41 @@ def catch_warnings():
56
56
fully_loaded = False
57
57
58
58
59
+ def module_matches (cw , prefix = '' ):
60
+ """Modules names to replace cw with"""
61
+ full = '%s.%s' % (prefix , cw ) if prefix else cw
62
+ matches = [name for name in modules
63
+ if (name .startswith (full ) and
64
+ name .find ('.' , len (full )) == - 1 )]
65
+ if prefix :
66
+ return [match [len (prefix )+ 1 :] for match in matches ]
67
+ else :
68
+ return matches
69
+
70
+ def attr_matches (cw , prefix = '' , only_modules = False ):
71
+ """Attributes to replace name with"""
72
+ full = '%s.%s' % (prefix , cw ) if prefix else cw
73
+ module_name , _ , name_after_dot = full .rpartition ('.' )
74
+ if module_name not in sys .modules :
75
+ return []
76
+ module = sys .modules [module_name ]
77
+ if only_modules :
78
+ matches = [name for name in dir (module )
79
+ if name .startswith (name_after_dot ) and
80
+ '%s.%s' % (module_name , name ) in sys .modules ]
81
+ else :
82
+ matches = [name for name in dir (module ) if name .startswith (name_after_dot )]
83
+ module_part , _ , _ = cw .rpartition ('.' )
84
+ if module_part :
85
+ return ['%s.%s' % (module_part , m ) for m in matches ]
86
+ return matches
87
+
88
+ def module_attr_matches (name ):
89
+ """Only attributes which are modules to replace name with"""
90
+ return attr_matches (name , prefix = '' , only_modules = True )
91
+
59
92
def complete (cursor_offset , line ):
60
93
"""Construct a full list of possibly completions for imports."""
61
- # TODO if this is done in a thread (as it prob will be in Windows) we'll need this
62
- # if not fully_loaded:
63
- # return []
64
94
tokens = line .split ()
65
95
if 'from' not in tokens and 'import' not in tokens :
66
96
return None
@@ -69,39 +99,6 @@ def complete(cursor_offset, line):
69
99
if result is None :
70
100
return None
71
101
72
- def module_matches (cw , prefix = '' ):
73
- """Modules names to replace cw with"""
74
- full = '%s.%s' % (prefix , cw ) if prefix else cw
75
- matches = [name for name in modules
76
- if (name .startswith (full ) and
77
- name .find ('.' , len (full )) == - 1 )]
78
- if prefix :
79
- return [match [len (prefix )+ 1 :] for match in matches ]
80
- else :
81
- return matches
82
-
83
- def attr_matches (cw , prefix = '' , only_modules = False ):
84
- """Attributes to replace name with"""
85
- full = '%s.%s' % (prefix , cw ) if prefix else cw
86
- module_name , _ , name_after_dot = full .rpartition ('.' )
87
- if module_name not in sys .modules :
88
- return []
89
- module = sys .modules [module_name ]
90
- if only_modules :
91
- matches = [name for name in dir (module )
92
- if name .startswith (name_after_dot ) and
93
- '%s.%s' % (module_name , name ) in sys .modules ]
94
- else :
95
- matches = [name for name in dir (module ) if name .startswith (name_after_dot )]
96
- module_part , _ , _ = cw .rpartition ('.' )
97
- if module_part :
98
- return ['%s.%s' % (module_part , m ) for m in matches ]
99
- return matches
100
-
101
- def module_attr_matches (name ):
102
- """Only attributes which are modules to replace name with"""
103
- return attr_matches (name , prefix = '' , only_modules = True )
104
-
105
102
if lineparts .current_from_import_from (cursor_offset , line ) is not None :
106
103
if lineparts .current_from_import_import (cursor_offset , line ) is not None :
107
104
# `from a import <b|>` completion
0 commit comments