forked from VimPlug/jedi
use_as_parent again and fast_parent_copy deals now with __slots__
This commit is contained in:
@@ -153,7 +153,20 @@ def fast_parent_copy(obj):
|
|||||||
new_obj = copy.copy(obj)
|
new_obj = copy.copy(obj)
|
||||||
new_elements[obj] = new_obj
|
new_elements[obj] = new_obj
|
||||||
|
|
||||||
items = new_obj.__dict__.items()
|
try:
|
||||||
|
items = new_obj.__dict__.items()
|
||||||
|
except AttributeError:
|
||||||
|
# __dict__ not available, because of __slots__
|
||||||
|
items = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
names = new_obj.__slots__
|
||||||
|
except AttributeError:
|
||||||
|
# __slots__ not available (normal)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
items += [(n, getattr(new_obj, n)) for n in names]
|
||||||
|
|
||||||
for key, value in items:
|
for key, value in items:
|
||||||
# replace parent (first try _parent and then parent)
|
# replace parent (first try _parent and then parent)
|
||||||
if key in ['parent', '_parent', '_parent_stmt'] \
|
if key in ['parent', '_parent', '_parent_stmt'] \
|
||||||
@@ -165,7 +178,7 @@ def fast_parent_copy(obj):
|
|||||||
setattr(new_obj, key, new_elements[value])
|
setattr(new_obj, key, new_elements[value])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
elif key in ['parent_stmt', 'parent_function', 'set_parent',
|
elif key in ['parent_stmt', 'parent_function', 'use_as_parent',
|
||||||
'module']:
|
'module']:
|
||||||
continue
|
continue
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
|
|||||||
@@ -1761,7 +1761,7 @@ class PyFuzzyParser(object):
|
|||||||
and not isinstance(self.scope, SubModule):
|
and not isinstance(self.scope, SubModule):
|
||||||
self.scope = self.module
|
self.scope = self.module
|
||||||
|
|
||||||
set_parent_scope = self.top_module if isinstance(self.scope,
|
use_as_parent_scope = self.top_module if isinstance(self.scope,
|
||||||
SubModule) else self.scope
|
SubModule) else self.scope
|
||||||
first_pos = self.start_pos
|
first_pos = self.start_pos
|
||||||
if tok == 'def':
|
if tok == 'def':
|
||||||
@@ -1838,14 +1838,14 @@ class PyFuzzyParser(object):
|
|||||||
debug.warning('syntax err, for flow started @%s',
|
debug.warning('syntax err, for flow started @%s',
|
||||||
self.start_pos[0])
|
self.start_pos[0])
|
||||||
if statement is not None:
|
if statement is not None:
|
||||||
statement.parent = set_parent_scope
|
statement.parent = use_as_parent_scope
|
||||||
if set_stmt is not None:
|
if set_stmt is not None:
|
||||||
set_stmt.parent = set_parent_scope
|
set_stmt.parent = use_as_parent_scope
|
||||||
else:
|
else:
|
||||||
debug.warning('syntax err, for flow incomplete @%s',
|
debug.warning('syntax err, for flow incomplete @%s',
|
||||||
self.start_pos[0])
|
self.start_pos[0])
|
||||||
if set_stmt is not None:
|
if set_stmt is not None:
|
||||||
set_stmt.parent = set_parent_scope
|
set_stmt.parent = use_as_parent_scope
|
||||||
|
|
||||||
elif tok in ['if', 'while', 'try', 'with'] + extended_flow:
|
elif tok in ['if', 'while', 'try', 'with'] + extended_flow:
|
||||||
added_breaks = []
|
added_breaks = []
|
||||||
@@ -1886,7 +1886,7 @@ class PyFuzzyParser(object):
|
|||||||
self.scope = s
|
self.scope = s
|
||||||
else:
|
else:
|
||||||
for i in inits:
|
for i in inits:
|
||||||
i.parent = set_parent_scope
|
i.parent = use_as_parent_scope
|
||||||
debug.warning('syntax err, flow started @%s',
|
debug.warning('syntax err, flow started @%s',
|
||||||
self.start_pos[0])
|
self.start_pos[0])
|
||||||
# returns
|
# returns
|
||||||
@@ -1900,7 +1900,7 @@ class PyFuzzyParser(object):
|
|||||||
|
|
||||||
stmt, tok = self._parse_statement()
|
stmt, tok = self._parse_statement()
|
||||||
if stmt is not None:
|
if stmt is not None:
|
||||||
stmt.parent = set_parent_scope
|
stmt.parent = use_as_parent_scope
|
||||||
try:
|
try:
|
||||||
func.returns.append(stmt)
|
func.returns.append(stmt)
|
||||||
# start_pos is the one of the return statement
|
# start_pos is the one of the return statement
|
||||||
@@ -1924,7 +1924,7 @@ class PyFuzzyParser(object):
|
|||||||
continue
|
continue
|
||||||
elif tok == 'assert':
|
elif tok == 'assert':
|
||||||
stmt, tok = self._parse_statement()
|
stmt, tok = self._parse_statement()
|
||||||
stmt.parent = set_parent_scope
|
stmt.parent = use_as_parent_scope
|
||||||
self.scope.asserts.append(stmt)
|
self.scope.asserts.append(stmt)
|
||||||
# default
|
# default
|
||||||
elif token_type in [tokenize.NAME, tokenize.STRING,
|
elif token_type in [tokenize.NAME, tokenize.STRING,
|
||||||
|
|||||||
Reference in New Issue
Block a user