forked from VimPlug/jedi
Avoid multiple getattrs instead of a single one, see also #1933
This commit is contained in:
@@ -9,7 +9,7 @@ import re
|
||||
import builtins
|
||||
import typing
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from jedi.inference.compiled.getattr_static import getattr_static
|
||||
|
||||
@@ -329,8 +329,11 @@ class DirectObjectAccess:
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def is_allowed_getattr(self, name, safe=True):
|
||||
def is_allowed_getattr(self, name, safe=True) -> Tuple[bool, bool]:
|
||||
# TODO this API is ugly.
|
||||
try:
|
||||
attr, is_get_descriptor = getattr_static(self._obj, name)
|
||||
except AttributeError:
|
||||
if not safe:
|
||||
# Unsafe is mostly used to check for __getattr__/__getattribute__.
|
||||
# getattr_static works for properties, but the underscore methods
|
||||
@@ -345,10 +348,7 @@ class DirectObjectAccess:
|
||||
except Exception:
|
||||
# Obviously has an attribute (probably a property) that
|
||||
# gets executed, so just avoid all exceptions here.
|
||||
return False, False
|
||||
try:
|
||||
attr, is_get_descriptor = getattr_static(self._obj, name)
|
||||
except AttributeError:
|
||||
pass
|
||||
return False, False
|
||||
else:
|
||||
if is_get_descriptor and type(attr) not in ALLOWED_DESCRIPTOR_ACCESS:
|
||||
|
||||
Reference in New Issue
Block a user