X Tutup
Skip to content

Commit 72e1c4b

Browse files
committed
Also handle function __doc__ where the signature is split over two or more lines
1 parent 2f4e69a commit 72e1c4b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
run: |
2727
python -m pip install --upgrade pip
2828
pip install -r requirements.txt
29-
pip install pytest pytest-cov urwid twisted watchdog "jedi >=0.16" babel "sphinx >=1.5"
29+
pip install urwid twisted watchdog "jedi >=0.16" babel "sphinx >=1.5"
30+
pip install pytest pytest-cov numpy
3031
- name: Build with Python ${{ matrix.python-version }}
3132
run: |
3233
python setup.py build

bpython/inspection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import inspect
2525
import keyword
2626
import pydoc
27+
import re
2728
from collections import namedtuple
2829

2930
from pygments.token import Token
@@ -173,7 +174,9 @@ def fixlongargs(f, argspec):
173174
argspec[3] = values
174175

175176

176-
getpydocspec_re = LazyReCompile(r"([a-zA-Z_][a-zA-Z0-9_]*?)\((.*?)\)")
177+
getpydocspec_re = LazyReCompile(
178+
r"([a-zA-Z_][a-zA-Z0-9_]*?)\((.*?)\)", re.DOTALL
179+
)
177180

178181

179182
def getpydocspec(f, func):
@@ -189,10 +192,10 @@ def getpydocspec(f, func):
189192
if not hasattr_safe(f, "__name__") or s.groups()[0] != f.__name__:
190193
return None
191194

192-
args = list()
193-
defaults = list()
195+
args = []
196+
defaults = []
194197
varargs = varkwargs = None
195-
kwonly_args = list()
198+
kwonly_args = []
196199
kwonly_defaults = dict()
197200
for arg in s.group(2).split(","):
198201
arg = arg.strip()

bpython/test/test_inspection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from bpython.test.fodder import encoding_latin1
77
from bpython.test.fodder import encoding_utf8
88

9+
try:
10+
import numpy
11+
except ImportError:
12+
numpy = None
13+
914

1015
foo_ascii_only = '''def foo():
1116
"""Test"""
@@ -113,6 +118,15 @@ def test_get_source_file(self):
113118
)
114119
self.assertEqual(encoding, "utf-8")
115120

121+
@unittest.skipUnless(numpy is not None, "requires numpy")
122+
def test_getfuncprops_numpy_array(self):
123+
props = inspection.getfuncprops("array", numpy.array)
124+
125+
self.assertEqual(props.func, "array")
126+
# This check might need an update in the future, but at least numpy >= 1.18 has
127+
# np.array(object, dtype=None, *, ...).
128+
self.assertEqual(props.argspec.args, ["object", "dtype"])
129+
116130

117131
class A:
118132
a = "a"

0 commit comments

Comments
 (0)
X Tutup