diff options
| author | Guido van Rossum <guido@python.org> | 1997-07-18 16:48:30 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1997-07-18 16:48:30 +0000 |
| commit | 740d4dc37e9a1a6c3e19ee5037dc94de4a75ada7 (patch) | |
| tree | c2f368ca13ac9e3caa8b6395b0d16dd31a921731 /Lib/lib-old | |
| parent | 6574ceb3f76ad85b0f272a78efbc74703e4d7537 (diff) | |
| download | cpython-740d4dc37e9a1a6c3e19ee5037dc94de4a75ada7.tar.gz | |
This module is now completely obsolete.
Noted this in the XXX comments.
Also, changed all three functions to use the attributes if they exist.
Diffstat (limited to 'Lib/lib-old')
| -rw-r--r-- | Lib/lib-old/codehack.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/lib-old/codehack.py b/Lib/lib-old/codehack.py index 1f16814224..6453db5e17 100644 --- a/Lib/lib-old/codehack.py +++ b/Lib/lib-old/codehack.py @@ -10,6 +10,8 @@ import linecache # XXX The functions getcodename() and getfuncname() are now obsolete # XXX as code and function objects now have a name attribute -- # XXX co.co_name and f.func_name. +# XXX getlineno() is now also obsolete because of the new attribute +# XXX of code objects, co.co_firstlineno. # Extract the function or class name from a code object. # This is a bit of a hack, since a code object doesn't contain @@ -34,6 +36,10 @@ identchars = string.letters + string.digits + '_' # Identifier characters _namecache = {} # The cache def getcodename(co): + try: + return co.co_name + except AttributeError: + pass key = `co` # arbitrary but uniquely identifying string if _namecache.has_key(key): return _namecache[key] filename = co.co_filename @@ -55,11 +61,19 @@ def getcodename(co): # Use the above routine to find a function's name. def getfuncname(func): + try: + return func.func_name + except AttributeError: + pass return getcodename(func.func_code) # A part of the above code to extract just the line number from a code object. def getlineno(co): + try: + return co.co_firstlineno + except AttributeError: + pass code = co.co_code if ord(code[0]) == SET_LINENO: return ord(code[1]) | ord(code[2]) << 8 |
