File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Original file line number Diff line number Diff line change 1
1
"""Implementation of __array_function__ overrides from NEP-18."""
2
2
import collections
3
3
import functools
4
+ import inspect
4
5
import os
5
6
import textwrap
6
7
@@ -34,6 +35,15 @@ def set_array_function_like_doc(public_api):
34
35
return public_api
35
36
36
37
38
+ def add_signature (function , docstring ):
39
+ try :
40
+ function .__signature__ = inspect ._signature_fromstr (
41
+ inspect .Signature , function ,
42
+ docstring .strip ().split ('\n ' )[0 ])
43
+ except ValueError :
44
+ pass
45
+
46
+
37
47
add_docstring (
38
48
implement_array_function ,
39
49
"""
@@ -213,6 +223,9 @@ def decorator(implementation):
213
223
if module is not None :
214
224
public_api .__module__ = module
215
225
226
+ if docs_from_dispatcher and dispatcher .__doc__ :
227
+ add_signature (public_api , dispatcher .__doc__ )
228
+
216
229
public_api ._implementation = implementation
217
230
218
231
return public_api
Original file line number Diff line number Diff line change 2
2
import subprocess
3
3
import pkgutil
4
4
import types
5
+ import inspect
5
6
import importlib
6
7
import warnings
7
8
@@ -471,3 +472,18 @@ def check_importable(module_name):
471
472
raise AssertionError ("Modules that are not really public but looked "
472
473
"public and can not be imported: "
473
474
"{}" .format (module_names ))
475
+
476
+ if sys .flags .optimize < 2 :
477
+
478
+ def test_all_function_have_signature ():
479
+ allowlist = {'concatenate' , 'where' }
480
+
481
+ for key , value in inspect .getmembers (numpy ):
482
+ if not inspect .isfunction (value ):
483
+ continue
484
+ if key in allowlist :
485
+ continue
486
+ try :
487
+ inspect .signature (value )
488
+ except ValueError :
489
+ raise AssertionError ("No signature found for {}" .format (key ))
You can’t perform that action at this time.
0 commit comments