Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit be7f001

Browse files
authored
Skip bad fused cython functions during scrape (microsoft#995)
1 parent b4c5018 commit be7f001

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Analysis/Ast/Impl/scrape_module.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ def safe_module_name(n):
149149
return '_mod_' + n.replace('.', '_')
150150
return n
151151

152+
def do_not_inspect(v):
153+
# https://github.com/Microsoft/python-language-server/issues/740
154+
# https://github.com/cython/cython/issues/1470
155+
if type(v).__name__ != "fused_cython_function":
156+
return False
157+
158+
# If a fused function has __defaults__, then attempting to access
159+
# __kwdefaults__ will fail if generated before cython 0.29.6.
160+
return bool(getattr(v, "__defaults__", False))
161+
152162
class Signature(object):
153163
# These two dictionaries start with Python 3 values.
154164
# There is an update below for Python 2 differences.
@@ -330,6 +340,9 @@ def __str__(self):
330340
return self.fullsig
331341

332342
def _init_argspec_fromsignature(self, defaults):
343+
if do_not_inspect(self.callable):
344+
return
345+
333346
try:
334347
sig = inspect.signature(self.callable)
335348
except Exception:
@@ -351,6 +364,9 @@ def _init_argspec_fromsignature(self, defaults):
351364
return self.name + str(sig)
352365

353366
def _init_restype_fromsignature(self):
367+
if do_not_inspect(self.callable):
368+
return
369+
354370
try:
355371
sig = inspect.signature(self.callable)
356372
except Exception:
@@ -366,6 +382,9 @@ def _init_restype_fromsignature(self):
366382
return 'return ' + ann
367383

368384
def _init_argspec_fromargspec(self, defaults):
385+
if do_not_inspect(self.callable):
386+
return
387+
369388
try:
370389
args = (getattr(inspect, 'getfullargspec', None) or inspect.getargspec)(self.callable)
371390
except Exception:

0 commit comments

Comments
 (0)