mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-17 21:34:12 +08:00
Python 2.7 compatibility.
This commit is contained in:
@@ -197,3 +197,15 @@ try:
|
||||
from itertools import zip_longest
|
||||
except ImportError:
|
||||
from itertools import izip_longest as zip_longest # Python 2
|
||||
|
||||
|
||||
def no_unicode_pprint(dct):
|
||||
"""
|
||||
Python 2/3 dict __repr__ may be different, because of unicode differens
|
||||
(with or without a `u` prefix). Normally in doctests we could use `pprint`
|
||||
to sort dicts and check for equality, but here we have to write a separate
|
||||
function to do that.
|
||||
"""
|
||||
import pprint
|
||||
s = pprint.pformat(dct)
|
||||
print(re.sub("u'", "'", s))
|
||||
|
||||
@@ -533,8 +533,6 @@ class Script(object):
|
||||
for n in imp_names:
|
||||
iw = imports.ImportWrapper(self._evaluator, n).follow()
|
||||
i = n.get_definition()
|
||||
if i.is_nested() and any(not isinstance(i, pr.Module) for i in iw):
|
||||
analysis.add(self._evaluator, 'import-error', i.namespace_names[-1])
|
||||
for node in sorted(nodes, key=lambda obj: obj.start_pos):
|
||||
#if not (isinstance(stmt.parent, pr.ForFlow) and stmt.parent.set_stmt == stmt):
|
||||
if node.type == 'expr_stmt':
|
||||
|
||||
@@ -439,7 +439,7 @@ def global_names_dict_generator(evaluator, scope, position):
|
||||
This function is used to include names from outer scopes. For example, when
|
||||
the current scope is function:
|
||||
|
||||
>>> from jedi._compatibility import u
|
||||
>>> from jedi._compatibility import u, no_unicode_pprint
|
||||
>>> from jedi.parser import Parser, load_grammar
|
||||
>>> parser = Parser(load_grammar(), u('''
|
||||
... x = ['a', 'b', 'c']
|
||||
@@ -453,12 +453,11 @@ def global_names_dict_generator(evaluator, scope, position):
|
||||
`global_names_dict_generator` is a generator. First it yields names from
|
||||
most inner scope.
|
||||
|
||||
>>> from pprint import pprint
|
||||
>>> from jedi.evaluate import Evaluator
|
||||
>>> evaluator = Evaluator(load_grammar())
|
||||
>>> scope = er.wrap(evaluator, scope)
|
||||
>>> pairs = list(global_names_dict_generator(evaluator, scope, (4, 0)))
|
||||
>>> pprint(pairs[0])
|
||||
>>> no_unicode_pprint(pairs[0])
|
||||
({'func': [], 'y': [<Name: y@4,4>]}, (4, 0))
|
||||
|
||||
Then it yields the names from one level "lower". In this example, this
|
||||
@@ -466,7 +465,7 @@ def global_names_dict_generator(evaluator, scope, position):
|
||||
None, because typically the whole module is loaded before the function is
|
||||
called.
|
||||
|
||||
>>> pprint(pairs[1])
|
||||
>>> no_unicode_pprint(pairs[1])
|
||||
({'func': [<Name: func@3,4>], 'x': [<Name: x@2,0>]}, None)
|
||||
|
||||
After that we have a few underscore names that are part of the module.
|
||||
|
||||
@@ -71,7 +71,8 @@ yield_stmt: yield_expr
|
||||
raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]
|
||||
import_stmt: import_name | import_from
|
||||
import_name: 'import' dotted_as_names
|
||||
import_from: ('from' ('.'* dotted_name | '.'+)
|
||||
# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
|
||||
import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
|
||||
'import' ('*' | '(' import_as_names ')' | import_as_names))
|
||||
import_as_name: NAME ['as' NAME]
|
||||
dotted_as_name: dotted_name ['as' NAME]
|
||||
|
||||
Reference in New Issue
Block a user