Skip to content

Commit 668bf06

Browse files
committed
Show __new__ docstrings. Fixes bpython#572
1 parent 2e25891 commit 668bf06

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

bpython/inspection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def getfuncprops(func, f):
231231
try:
232232
is_bound_method = ((inspect.ismethod(f) and f.__self__ is not None)
233233
or (func_name == '__init__' and not
234-
func.endswith('.__init__')))
234+
func.endswith('.__init__'))
235+
or (func_name == '__new__' and not
236+
func.endswith('.__new__')))
235237
except:
236238
# if f is a method from a xmlrpclib.Server instance, func_name ==
237239
# '__init__' throws xmlrpclib.Fault (see #202)

bpython/repl.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,21 @@ def get_args(self):
527527
return False
528528

529529
if inspect.isclass(f):
530-
try:
531-
if f.__init__ is not object.__init__:
532-
f = f.__init__
533-
except AttributeError:
534-
return None
530+
class_f = None
531+
532+
if (hasattr(f, '__init__') and
533+
f.__init__ is not object.__init__):
534+
class_f = f.__init__
535+
if ((not class_f or
536+
not inspection.getfuncprops(func, class_f)) and
537+
hasattr(f, '__new__') and
538+
f.__new__ is not object.__new__ and
539+
f.__new__.__class__ is not object.__new__.__class__): # py3
540+
class_f = f.__new__
541+
542+
if class_f:
543+
f = class_f
544+
535545
self.current_func = f
536546
self.funcprops = inspection.getfuncprops(func, f)
537547
if self.funcprops:

bpython/test/test_repl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def setUp(self):
138138
self.repl.push(" def spam(self, a, b, c):\n", False)
139139
self.repl.push(" pass\n", False)
140140
self.repl.push("\n", False)
141+
self.repl.push("class SpammitySpam(object):\n", False)
142+
self.repl.push(" def __init__(self, a, b, c):\n", False)
143+
self.repl.push(" pass\n", False)
144+
self.repl.push("\n", False)
145+
self.repl.push("class WonderfulSpam(object):\n", False)
146+
self.repl.push(" def __new__(self, a, b, c):\n", False)
147+
self.repl.push(" pass\n", False)
148+
self.repl.push("\n", False)
141149
self.repl.push("o = Spam()\n", False)
142150
self.repl.push("\n", False)
143151

@@ -207,6 +215,13 @@ def test_nonexistent_name(self):
207215
self.set_input_line("spamspamspam(")
208216
self.assertFalse(self.repl.get_args())
209217

218+
def test_issue572(self):
219+
self.set_input_line("SpammitySpam(")
220+
self.assertTrue(self.repl.get_args())
221+
222+
self.set_input_line("WonderfulSpam(")
223+
self.assertTrue(self.repl.get_args())
224+
210225

211226
class TestGetSource(unittest.TestCase):
212227
def setUp(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy