diff --git a/jedi/helpers.py b/jedi/helpers.py index 773b2150..b1fe2a62 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -153,7 +153,20 @@ def fast_parent_copy(obj): new_obj = copy.copy(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: # replace parent (first try _parent and then parent) if key in ['parent', '_parent', '_parent_stmt'] \ @@ -165,7 +178,7 @@ def fast_parent_copy(obj): setattr(new_obj, key, new_elements[value]) except KeyError: pass - elif key in ['parent_stmt', 'parent_function', 'set_parent', + elif key in ['parent_stmt', 'parent_function', 'use_as_parent', 'module']: continue elif isinstance(value, list): diff --git a/jedi/parsing.py b/jedi/parsing.py index 7bbad908..44c55f3d 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -1761,7 +1761,7 @@ class PyFuzzyParser(object): and not isinstance(self.scope, SubModule): 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 first_pos = self.start_pos if tok == 'def': @@ -1838,14 +1838,14 @@ class PyFuzzyParser(object): debug.warning('syntax err, for flow started @%s', self.start_pos[0]) if statement is not None: - statement.parent = set_parent_scope + statement.parent = use_as_parent_scope if set_stmt is not None: - set_stmt.parent = set_parent_scope + set_stmt.parent = use_as_parent_scope else: debug.warning('syntax err, for flow incomplete @%s', self.start_pos[0]) 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: added_breaks = [] @@ -1886,7 +1886,7 @@ class PyFuzzyParser(object): self.scope = s else: for i in inits: - i.parent = set_parent_scope + i.parent = use_as_parent_scope debug.warning('syntax err, flow started @%s', self.start_pos[0]) # returns @@ -1900,7 +1900,7 @@ class PyFuzzyParser(object): stmt, tok = self._parse_statement() if stmt is not None: - stmt.parent = set_parent_scope + stmt.parent = use_as_parent_scope try: func.returns.append(stmt) # start_pos is the one of the return statement @@ -1924,7 +1924,7 @@ class PyFuzzyParser(object): continue elif tok == 'assert': stmt, tok = self._parse_statement() - stmt.parent = set_parent_scope + stmt.parent = use_as_parent_scope self.scope.asserts.append(stmt) # default elif token_type in [tokenize.NAME, tokenize.STRING,