Show More
@@ -420,7 +420,6 b' class Inspector(Colorable):' | |||
|
420 | 420 | |
|
421 | 421 | if inspect.isclass(obj): |
|
422 | 422 | header = self.__head('Class constructor information:\n') |
|
423 | obj = obj.__init__ | |
|
424 | 423 | elif (not py3compat.PY3) and type(obj) is types.InstanceType: |
|
425 | 424 | obj = obj.__call__ |
|
426 | 425 | |
@@ -766,23 +765,28 b' class Inspector(Colorable):' | |||
|
766 | 765 | # Constructor docstring for classes |
|
767 | 766 | if inspect.isclass(obj): |
|
768 | 767 | out['isclass'] = True |
|
769 | # reconstruct the function definition and print it: | |
|
768 | ||
|
769 | # get the function signature: | |
|
770 | try: | |
|
771 | init_def = self._getdef(obj, oname) | |
|
772 | except AttributeError: | |
|
773 | init_def = None | |
|
774 | else: | |
|
775 | out['init_definition'] = self.format(init_def) | |
|
776 | ||
|
777 | # get the __init__ docstring | |
|
770 | 778 | try: |
|
771 |
obj_init = |
|
|
779 | obj_init = obj.__init__ | |
|
772 | 780 | except AttributeError: |
|
773 | 781 | init_def = init_ds = None |
|
774 | 782 | else: |
|
775 | init_def = self._getdef(obj_init,oname) | |
|
776 | 783 | init_ds = getdoc(obj_init) |
|
777 | 784 | # Skip Python's auto-generated docstrings |
|
778 | 785 | if init_ds == _object_init_docstring: |
|
779 | 786 | init_ds = None |
|
780 | 787 | |
|
781 |
if |
|
|
782 |
|
|
|
783 | out['init_definition'] = self.format(init_def) | |
|
784 | if init_ds: | |
|
785 | out['init_docstring'] = init_ds | |
|
788 | if init_ds: | |
|
789 | out['init_docstring'] = init_ds | |
|
786 | 790 | |
|
787 | 791 | # and class docstring for instances: |
|
788 | 792 | else: |
@@ -1,27 +1,17 b'' | |||
|
1 | 1 | """Tests for the object inspection functionality. |
|
2 | 2 | """ |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (C) 2010-2011 The IPython Development Team. | |
|
5 | # | |
|
6 | # Distributed under the terms of the BSD License. | |
|
7 | # | |
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |
|
9 | #----------------------------------------------------------------------------- | |
|
10 | 3 | |
|
11 | #----------------------------------------------------------------------------- | |
|
12 | # Imports | |
|
13 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (c) IPython Development Team. | |
|
5 | # Distributed under the terms of the Modified BSD License. | |
|
6 | ||
|
14 | 7 | from __future__ import print_function |
|
15 | 8 | |
|
16 | # Stdlib imports | |
|
17 | 9 | import os |
|
18 | 10 | import re |
|
19 | 11 | import sys |
|
20 | 12 | |
|
21 | # Third-party imports | |
|
22 | 13 | import nose.tools as nt |
|
23 | 14 | |
|
24 | # Our own imports | |
|
25 | 15 | from .. import oinspect |
|
26 | 16 | from IPython.core.magic import (Magics, magics_class, line_magic, |
|
27 | 17 | cell_magic, line_cell_magic, |
@@ -32,6 +22,7 b' from IPython.testing.decorators import skipif' | |||
|
32 | 22 | from IPython.testing.tools import AssertPrints |
|
33 | 23 | from IPython.utils.path import compress_user |
|
34 | 24 | from IPython.utils import py3compat |
|
25 | from IPython.utils.signatures import Signature, Parameter | |
|
35 | 26 | |
|
36 | 27 | |
|
37 | 28 | #----------------------------------------------------------------------------- |
@@ -49,7 +40,7 b' ip = get_ipython()' | |||
|
49 | 40 | # defined, if any code is inserted above, the following line will need to be |
|
50 | 41 | # updated. Do NOT insert any whitespace between the next line and the function |
|
51 | 42 | # definition below. |
|
52 |
THIS_LINE_NUMBER = |
|
|
43 | THIS_LINE_NUMBER = 43 # Put here the actual number of this line | |
|
53 | 44 | def test_find_source_lines(): |
|
54 | 45 | nt.assert_equal(oinspect.find_source_lines(test_find_source_lines), |
|
55 | 46 | THIS_LINE_NUMBER+1) |
@@ -120,6 +111,14 b' class Call(object):' | |||
|
120 | 111 | def method(self, x, z=2): |
|
121 | 112 | """Some method's docstring""" |
|
122 | 113 | |
|
114 | class HasSignature(object): | |
|
115 | """This is the class docstring.""" | |
|
116 | __signature__ = Signature([Parameter('test', Parameter.POSITIONAL_OR_KEYWORD)]) | |
|
117 | ||
|
118 | def __init__(self, *args): | |
|
119 | """This is the init docstring""" | |
|
120 | ||
|
121 | ||
|
123 | 122 | class SimpleClass(object): |
|
124 | 123 | def method(self, x, z=2): |
|
125 | 124 | """Some method's docstring""" |
@@ -282,7 +281,7 b' def test_info():' | |||
|
282 | 281 | nt.assert_equal(i['docstring'], Call.__doc__) |
|
283 | 282 | nt.assert_equal(i['source'], None) |
|
284 | 283 | nt.assert_true(i['isclass']) |
|
285 |
nt.assert_equal(i['init_definition'], "Call( |
|
|
284 | nt.assert_equal(i['init_definition'], "Call(x, y=1)\n") | |
|
286 | 285 | nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) |
|
287 | 286 | |
|
288 | 287 | i = inspector.info(Call, detail_level=1) |
@@ -307,6 +306,11 b' def test_info():' | |||
|
307 | 306 | nt.assert_equal(i['type_name'], 'instance') |
|
308 | 307 | nt.assert_equal(i['docstring'], OldStyle.__doc__) |
|
309 | 308 | |
|
309 | def test_class_signature(): | |
|
310 | info = inspector.info(HasSignature, 'HasSignature') | |
|
311 | nt.assert_equal(info['init_definition'], "HasSignature(test)\n") | |
|
312 | nt.assert_equal(info['init_docstring'], HasSignature.__init__.__doc__) | |
|
313 | ||
|
310 | 314 | def test_info_awkward(): |
|
311 | 315 | # Just test that this doesn't throw an error. |
|
312 | 316 | i = inspector.info(Awkward()) |
General Comments 0
You need to be logged in to leave comments.
Login now