Skip to content

Show __new__ docstrings. Fixes #572 #576

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
Nov 28, 2015
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
4 changes: 3 additions & 1 deletion bpython/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def getfuncprops(func, f):
try:
is_bound_method = ((inspect.ismethod(f) and f.__self__ is not None)
or (func_name == '__init__' and not
func.endswith('.__init__')))
func.endswith('.__init__'))
or (func_name == '__new__' and not
func.endswith('.__new__')))
except:
# if f is a method from a xmlrpclib.Server instance, func_name ==
# '__init__' throws xmlrpclib.Fault (see #202)
Expand Down
20 changes: 15 additions & 5 deletions bpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,21 @@ def get_args(self):
return False

if inspect.isclass(f):
try:
if f.__init__ is not object.__init__:
f = f.__init__
except AttributeError:
return None
class_f = None

if (hasattr(f, '__init__') and
f.__init__ is not object.__init__):
class_f = f.__init__
if ((not class_f or
not inspection.getfuncprops(func, class_f)) and
hasattr(f, '__new__') and
f.__new__ is not object.__new__ and
f.__new__.__class__ is not object.__new__.__class__): # py3
class_f = f.__new__

if class_f:
f = class_f

self.current_func = f
self.funcprops = inspection.getfuncprops(func, f)
if self.funcprops:
Expand Down
15 changes: 15 additions & 0 deletions bpython/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ def setUp(self):
self.repl.push(" def spam(self, a, b, c):\n", False)
self.repl.push(" pass\n", False)
self.repl.push("\n", False)
self.repl.push("class SpammitySpam(object):\n", False)
self.repl.push(" def __init__(self, a, b, c):\n", False)
self.repl.push(" pass\n", False)
self.repl.push("\n", False)
self.repl.push("class WonderfulSpam(object):\n", False)
self.repl.push(" def __new__(self, a, b, c):\n", False)
self.repl.push(" pass\n", False)
self.repl.push("\n", False)
self.repl.push("o = Spam()\n", False)
self.repl.push("\n", False)

Expand Down Expand Up @@ -207,6 +215,13 @@ def test_nonexistent_name(self):
self.set_input_line("spamspamspam(")
self.assertFalse(self.repl.get_args())

def test_issue572(self):
self.set_input_line("SpammitySpam(")
self.assertTrue(self.repl.get_args())

self.set_input_line("WonderfulSpam(")
self.assertTrue(self.repl.get_args())


class TestGetSource(unittest.TestCase):
def setUp(self):
Expand Down