Skip to content

Fix __signature__ support if object has a __file__ #992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bpython/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,13 @@ def getfuncprops(func: str, f: Callable) -> Optional[FuncProps]:
return None
try:
argspec = _get_argspec_from_signature(f)
fprops = FuncProps(
func, _fix_default_values(f, argspec), is_bound_method
)
try:
argspec = _fix_default_values(f, argspec)
except KeyError as ex:
# Parsing of the source failed. If f has a __signature__, we trust it.
if not hasattr(f, "__signature__"):
raise ex
fprops = FuncProps(func, argspec, is_bound_method)
except (TypeError, KeyError, ValueError):
argspec_pydoc = _getpydocspec(f)
if argspec_pydoc is None:
Expand Down
19 changes: 13 additions & 6 deletions bpython/test/test_repl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import inspect
import os
import socket
import sys
import tempfile
Expand Down Expand Up @@ -523,13 +524,19 @@ def __init__(self, *args, **kwargs):
inspect.Parameter("pinetree", inspect.Parameter.KEYWORD_ONLY),
])
"""
for line in code.split("\n"):
print(line[8:])
self.repl.push(line[8:])
code = [x[8:] for x in code.split("\n")]
for line in code:
self.repl.push(line)

self.assertTrue(self.repl.complete())
self.assertTrue(hasattr(self.repl.matches_iter, "matches"))
self.assertEqual(self.repl.matches_iter.matches, ["apple2=", "apple="])
with mock.patch(
"bpython.inspection.inspect.getsourcelines",
return_value=(code, None),
):
self.assertTrue(self.repl.complete())
self.assertTrue(hasattr(self.repl.matches_iter, "matches"))
self.assertEqual(
self.repl.matches_iter.matches, ["apple2=", "apple="]
)


if __name__ == "__main__":
Expand Down