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