From e4b6ede41fdf2f4a7ebef32861c498b5e04ae0ae Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 19 Apr 2019 16:15:28 -0700 Subject: [PATCH] Skip bad fused cython functions during scrape --- src/Analysis/Ast/Impl/scrape_module.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Analysis/Ast/Impl/scrape_module.py b/src/Analysis/Ast/Impl/scrape_module.py index c0de7239f..794d613e2 100644 --- a/src/Analysis/Ast/Impl/scrape_module.py +++ b/src/Analysis/Ast/Impl/scrape_module.py @@ -149,6 +149,16 @@ def safe_module_name(n): return '_mod_' + n.replace('.', '_') return n +def do_not_inspect(v): + # https://github.com/Microsoft/python-language-server/issues/740 + # https://github.com/cython/cython/issues/1470 + if type(v).__name__ != "fused_cython_function": + return False + + # If a fused function has __defaults__, then attempting to access + # __kwdefaults__ will fail if generated before cython 0.29.6. + return bool(getattr(v, "__defaults__", False)) + class Signature(object): # These two dictionaries start with Python 3 values. # There is an update below for Python 2 differences. @@ -330,6 +340,9 @@ def __str__(self): return self.fullsig def _init_argspec_fromsignature(self, defaults): + if do_not_inspect(self.callable): + return + try: sig = inspect.signature(self.callable) except Exception: @@ -351,6 +364,9 @@ def _init_argspec_fromsignature(self, defaults): return self.name + str(sig) def _init_restype_fromsignature(self): + if do_not_inspect(self.callable): + return + try: sig = inspect.signature(self.callable) except Exception: @@ -366,6 +382,9 @@ def _init_restype_fromsignature(self): return 'return ' + ann def _init_argspec_fromargspec(self, defaults): + if do_not_inspect(self.callable): + return + try: args = (getattr(inspect, 'getfullargspec', None) or inspect.getargspec)(self.callable) except Exception: