Commit Graph

60 Commits

Author SHA1 Message Date
Raymond Hettinger dbecd93b72 Replace list of constants with tuples of constants. 2005-02-06 06:57:08 +00:00
Johannes Gijsbers 1542f34c42 Patch #1011890: fix inspect.getsource breaking with line-continuation &
more. Thanks to Simon Percivall!

The patch makes changes to inspect.py in two places:

* the pattern to match against functions at line 436 is
modified: lambdas should be matched even if not
preceded by whitespace, as long as "lambda" isn't part
of another word.

* the BlockFinder class is heavily modified. Changes are:
- checking for "def", "class" or "lambda" names
before setting self.started to True. Then checking the
same line for word characters after the colon (if the
colon is on that line). If so, and the line does not
end with a line continuation marker, raise EndOfBlock
immediately.
- adding self.passline to show that the line is to be
included and no more checking is necessary on that
line. Since a NEWLINE token is not generated when a
line continuation marker exists, this allows getsource
to continue with these functions even if the following
line would not be indented.

Also add a bunch of
'quite-unlikely-to-occur-in-real-life-but-working-anyway' tests.
2004-12-12 16:46:28 +00:00
Raymond Hettinger 61656203cd Import no longer needed. 2004-09-20 18:08:31 +00:00
Skip Montanaro 13dea5a42b Raymond reminded me to use DSU key 2004-09-20 16:43:30 +00:00
Skip Montanaro 41f89a4f3d Sort classes by fully qualified name. In the common case where you are
displaying a set of classes from one module it doesn't matter, but if you
are displaying a large class tree from multiple modules it improves the
display to sort by module.name.
2004-09-20 15:40:38 +00:00
Johannes Gijsbers 9324526a76 Use __module__ attribute when available instead of using isclass() predicate
(functions and methods have grown the __module__ attribute too). See bug #570300.
2004-09-11 15:53:22 +00:00
Johannes Gijsbers c473c99d16 Patch #1006219: let inspect.getsource show '@' decorators and add tests for
this (which are rather ugly, but it'll have to do until test_inspect gets a
major overhaul and a conversion to unittest). Thanks Simon Percivall!
2004-08-18 12:40:31 +00:00
Matthias Klose 2e829c0214 - Bug #891637, patch #1005466: fix inspect.getargs() crash on def foo((bar)). 2004-08-15 17:04:33 +00:00
Brett Cannon b3de2e13ba 'inspect' was not listing the functions in a module properly if the module was
reached through a symlink (was comparing path of module to path to function and
were not matching because of the symlink).  os.path.realpath() is now used to
solve this discrepency.

Closes bug #570300.  Thanks Johannes Gijsbers for the fix.
2004-08-13 18:46:24 +00:00
Raymond Hettinger a050171ee9 SF bug #973092: inspect.getframeinfo bug if 'context' is to big
Make sure the start argument is not negative.
2004-06-15 11:22:53 +00:00
Andrew M. Kuchling ba8b6bc86f [Bug #954364] inspect.getframeinfo() sometimes produces incorrect traceback line #s; fix is to look at tb.tb_lineno, not tb.frame.f_lineno. Patch from Robin Becker and me. 2004-06-05 14:11:59 +00:00
Raymond Hettinger 3375fc5a3b Apply extract functions instead of lambda. 2003-12-01 20:12:15 +00:00
Raymond Hettinger 6b59f5f3fd Let library modules use the new keyword arguments for list.sort(). 2003-10-16 05:53:16 +00:00
Tim Peters 478c10554b Whitespace normalization. 2003-06-29 05:46:54 +00:00
Jeremy Hylton ab91902f6f A bit o' reformatting and removal of non-_getframe currentframe(). 2003-06-27 18:41:20 +00:00
Jeremy Hylton 6496788e7a Fix for SF bug 620190: getargspec() doesn't work with methods. 2003-06-27 18:14:39 +00:00
Brett Cannon 4a671fe634 Return None to signal that the module the object was defined in was not found when object has no __name__ attr but is needed to figure out location of object. 2003-06-15 22:33:28 +00:00
Martin v. Löwis e59e2bab8f Patch #711902: Cause pydoc to show data descriptor __doc__ strings. 2003-05-03 09:09:02 +00:00
Ka-Ping Yee b38bbbd387 Make module lookup a little more robust (certain kinds of fiddling to
sys.modules previously produced an exception).
2003-03-28 16:29:50 +00:00
Raymond Hettinger 2e7b748a9e SF patch #634557: inspect.BlockFinder didn't do a good enough job finding
the end of code blocks.

Patch contributed by Patrick O'Brien.
2003-01-19 13:21:20 +00:00
Raymond Hettinger 2d375f78a5 SF bug #661184: inspect.getsource bug
inspect.getsource would crash with one line definitions like:
   def f(x): return x
or
   f = lambda x: x
2003-01-14 02:19:36 +00:00
Ka-Ping Yee a59ef7bbe0 getdoc():
Remove leading whitespace from first line; remove leading and
    trailing blank lines from docstrings.  (Patch 645938 submitted
    by David Goodger.)
2002-11-30 03:53:15 +00:00
Michael W. Hudson dd32a91cc0 This is my patch
[ 587993 ] SET_LINENO killer

Remove SET_LINENO.  Tracing is now supported by inspecting co_lnotab.

Many sundry changes to document and adapt to this change.
2002-08-15 14:59:02 +00:00
Martin v. Löwis 09776b7afd Add encoding declaration. 2002-08-04 17:22:59 +00:00
Raymond Hettinger e0d4972acc Replaced .keys() with dictionary iterators 2002-06-02 18:55:56 +00:00
Raymond Hettinger 54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Raymond Hettinger 936654bce0 Replaced boolean test with is None 2002-06-01 03:06:31 +00:00
Michael W. Hudson 755f75eef8 Use types.StringTypes instead of explicit (str, unicode) list 2002-05-20 17:29:46 +00:00
Fred Drake d451ec1cdb Clean up uses of some deprecated features.
Reported by Neal Norwitz on python-dev.
2002-04-26 02:29:55 +00:00
Jeremy Hylton b4c17c8992 Fix getcomments() so that it doesn't fail with TypeErrors.
It appears that getcomments() can get called for classes defined in
C.  Since these don't have source code, it can't do anything useful.
A function buried many levels deep was raising a TypeError that was
not caught.

Who knows why this broke...
2002-03-28 23:01:56 +00:00
Skip Montanaro a959a36288 tighten up unqualified except in currentframe()
see bug 411881
2002-03-25 21:37:54 +00:00
Neil Schemenauer f06f8530f1 Use linecache for loading source code. Closes SF patch 490374. 2002-03-23 23:51:04 +00:00
Tim Peters 2400831773 SF patch 530070: pydoc regression, from Martin and Guido.
Change the way __doc__ is handled, to avoid blowing up on non-string
__doc__ values.
2002-03-17 18:56:20 +00:00
Neal Norwitz 8a11f5dc7b SF #515015, raise exception if code not found in findsource() 2002-03-13 03:14:26 +00:00
Guido van Rossum 687ae00460 Get rid of __defined__ and tp_defined -- there's no need to
distinguish __dict__ and __defined__ any more.  In the C structure,
tp_cache takes its place -- but this hasn't been implemented yet.
2001-10-15 22:03:32 +00:00
Tim Peters 13b49d3374 New function classify_class_attrs(). As a number of SF bug reports
point out, pydoc doesn't tell you where class attributes were defined,
gets several new 2.2 features wrong, and isn't aware of some new features
checked in on Thursday <wink>.  pydoc is hampered in part because
inspect.py has the same limitations.  Alas, I can't think of a way to
fix this within the current architecture of inspect/pydoc:  it's simply
not possible in 2.2 to figure out everything needed just from examining
the object you get back from class.attr.  You also need the class
context, and the method resolution order, and tests against various things
that simply didn't exist before.  OTOH, knowledge of how to do that is
getting quite complex, so doesn't belong in pydoc.

classify_class_attrs takes a different approach, analyzing all
the class attrs "at once", and returning the most interesting stuff for
each, all in one gulp.  pydoc needs to be reworked to use this for
classes (instead of the current "filter dir(class) umpteen times against
assorted predicates" approach).
2001-09-23 02:00:29 +00:00
Tim Peters e0b2d7ac9a Add a function to compute a class's method resolution order. This is
easy for 2.2 new-style classes, but trickier for classic classes, and
different approaches are needed "depending".  The function will allow
later code to treat all flavors of classes uniformly.
2001-09-22 06:10:55 +00:00
Tim Peters f1d90b965e Ensure that isfunction(obj) and (the new) ismethoddescriptor(obj) never
both return true.  This restores pydoc's ability to deduce argument lists
for functions and methods coded in Python.
2001-09-20 05:47:55 +00:00
Tim Peters 536d2262f7 After much thrashing, I believe this is a truly minimal patch to teach
pydoc how to do something sensible with 2.2 descriptors.  To see the
difference, browse __builtin__ via pydoc before and after the patch.
2001-09-20 05:13:38 +00:00
Tim Peters 28bc59f116 In a world with a growing number of subclassable types, replace
type(x) is T
tests with
    isinstance(x, T)
Also got rid of a future-generators import, left over from code that
wasn't intended to get checked in.
2001-09-16 08:40:16 +00:00
Guido van Rossum 54e54c6877 The first batch of changes recommended by the fixdiv tool. These are
mostly changes of / operators into //.  Once or twice I did more or
less than recommended.
2001-09-04 19:14:14 +00:00
Guido van Rossum b09f7ed623 Preliminary support for "from __future__ import generators" to enable
the yield statement.  I figure we have to have this in before I can
release 2.2a1 on Wednesday.

Note: test_generators is currently broken, I'm counting on Tim to fix
this.
2001-07-15 21:08:29 +00:00
Tim Peters 4efb6e9643 Turns out Neil didn't intend for *all* of his gen-branch work to get
committed.

tokenize.py:  I like these changes, and have tested them extensively
without even realizing it, so I just updated the docstring and the docs.

tabnanny.py:  Also liked this, but did a little code fiddling.  I should
really rewrite this to *exploit* generators, but that's near the bottom
of my effort/benefit scale so doubt I'll get to it anytime soon (it
would be most useful as a non-trivial example of ideal use of generators;
but test_generators.py has already grown plenty of food-for-thought
examples).

inspect.py:  I'm sure Ping intended for this to continue running even
under 1.5.2, so I reverted this to the last pre-gen-branch version.  The
"bugfix" I checked in in-between was actually repairing a bug *introduced*
by the conversion to generators, so it's OK that the reverted version
doesn't reflect that checkin.
2001-06-29 23:51:08 +00:00
Tim Peters 5ca576ed0a Merging the gen-branch into the main line, at Guido's direction. Yay!
Bugfix candidate in inspect.py:  it was referencing "self" outside of
a method.
2001-06-18 22:08:13 +00:00
Ka-Ping Yee 022171fa21 Clean up isroutine(). 2001-04-13 14:04:02 +00:00
Ka-Ping Yee c99e0f1862 Robustify getfile() against classes that lie about their __module__s
(such as the exceptions in _weakref and _locale!)
2001-04-13 12:10:40 +00:00
Ka-Ping Yee 202c99b2e0 Remove duplicate type objects from isroutine() and isbuiltin().
Make getmodule() on a module return the module itself.
2001-04-13 09:15:08 +00:00
Ka-Ping Yee b910efe8a9 Robustify getcomments() so it doesn't crash on empty files. 2001-04-12 13:17:17 +00:00
Ka-Ping Yee 4d6fc7fae1 Add getmodulename() and getmoduleinfo() routines to inspect filenames. 2001-04-10 11:43:00 +00:00
Ka-Ping Yee a9c6c8dab5 Extend isclass() to work for extension classes (by looking for __bases__). 2001-03-23 15:29:59 +00:00