mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
parentheses work now in import statements (tested)
This commit is contained in:
@@ -2,6 +2,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import types
|
import types
|
||||||
|
import io
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import debug
|
import debug
|
||||||
@@ -71,7 +72,7 @@ class Parser(CachedModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sys.hexversion >= 0x03000000:
|
if sys.hexversion >= 0x03000000:
|
||||||
map_types['file object'] = 'import io; return io.TextWrapper(file)'
|
map_types['file object'] = 'import io; return io.TextIOWrapper(file)'
|
||||||
|
|
||||||
module_cache = {}
|
module_cache = {}
|
||||||
|
|
||||||
@@ -244,7 +245,11 @@ class Parser(CachedModule):
|
|||||||
|
|
||||||
# variables
|
# variables
|
||||||
for name, value in stmts.items():
|
for name, value in stmts.items():
|
||||||
if type(value) == types.FileType:
|
if sys.hexversion >= 0x03000000:
|
||||||
|
file_type = io.TextIOWrapper
|
||||||
|
else:
|
||||||
|
file_type = types.FileType
|
||||||
|
if type(value) == file_type:
|
||||||
value = 'open()'
|
value = 'open()'
|
||||||
elif type(value).__name__ in ['int', 'bool', 'float',
|
elif type(value).__name__ in ['int', 'bool', 'float',
|
||||||
'dict', 'list', 'tuple']:
|
'dict', 'list', 'tuple']:
|
||||||
|
|||||||
16
parsing.py
16
parsing.py
@@ -32,6 +32,7 @@ from _compatibility import next, literal_eval, tokenize_func, BytesIO
|
|||||||
|
|
||||||
import tokenize
|
import tokenize
|
||||||
import re
|
import re
|
||||||
|
import keyword
|
||||||
|
|
||||||
import debug
|
import debug
|
||||||
|
|
||||||
@@ -1007,9 +1008,18 @@ class PyFuzzyParser(object):
|
|||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
imports = []
|
imports = []
|
||||||
|
brackets = False
|
||||||
|
continue_kw = [",", ";", "\n", ')'] \
|
||||||
|
+ list(set(keyword.kwlist) - set(['as']))
|
||||||
while True:
|
while True:
|
||||||
|
token_type, tok, indent = self.next()
|
||||||
|
if brackets and tok == '\n':
|
||||||
|
self.next()
|
||||||
|
if tok == '(': # python allows only one `(` in the statement.
|
||||||
|
brackets = True
|
||||||
|
self.next()
|
||||||
name, token_type, tok, start_indent, start_line = \
|
name, token_type, tok, start_indent, start_line = \
|
||||||
self._parsedotname()
|
self._parsedotname(self.current)
|
||||||
if not name:
|
if not name:
|
||||||
break
|
break
|
||||||
name2 = None
|
name2 = None
|
||||||
@@ -1019,9 +1029,9 @@ class PyFuzzyParser(object):
|
|||||||
name2 = Name(name2, start_indent2, start_line, self.line_nr)
|
name2 = Name(name2, start_indent2, start_line, self.line_nr)
|
||||||
i = Name(name, start_indent, start_line, self.line_nr)
|
i = Name(name, start_indent, start_line, self.line_nr)
|
||||||
imports.append((i, name2))
|
imports.append((i, name2))
|
||||||
while tok not in [",", ";", "\n"]:
|
while tok not in continue_kw:
|
||||||
token_type, tok, indent = self.next()
|
token_type, tok, indent = self.next()
|
||||||
if tok != ",":
|
if not (tok == "," or brackets and tok == '\n'):
|
||||||
break
|
break
|
||||||
return imports
|
return imports
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,23 @@ import os
|
|||||||
#? ['dirname']
|
#? ['dirname']
|
||||||
os.path.dirname
|
os.path.dirname
|
||||||
|
|
||||||
|
from itertools import (tee,
|
||||||
|
islice)
|
||||||
|
#? ['islice']
|
||||||
|
islice
|
||||||
|
|
||||||
|
from functools import (partial, wraps)
|
||||||
|
#? ['wraps']
|
||||||
|
wraps
|
||||||
|
|
||||||
|
from keyword import kwlist, \
|
||||||
|
iskeyword
|
||||||
|
#? ['kwlist']
|
||||||
|
kwlist
|
||||||
|
|
||||||
|
from tokenize import io
|
||||||
|
tokenize.generate_tokens
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# builtins
|
# builtins
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
from a import (b
|
||||||
|
def blub():
|
||||||
|
return 0
|
||||||
def openbrace():
|
def openbrace():
|
||||||
asdf = 3
|
asdf = 3
|
||||||
asdf
|
asdf
|
||||||
|
|||||||
Reference in New Issue
Block a user