diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2010-08-17 10:18:16 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2010-08-17 10:18:16 (GMT) |
commit | 09c8123e6f2d01444b03e7971f3e3dec37474490 (patch) | |
tree | ef40c7e94ccba25249313ecd46de2b131e99fd8a /Lib/inspect.py | |
parent | 77203adb7e3c50775b768a846ebc03514e69be77 (diff) | |
download | cpython-09c8123e6f2d01444b03e7971f3e3dec37474490.zip cpython-09c8123e6f2d01444b03e7971f3e3dec37474490.tar.gz cpython-09c8123e6f2d01444b03e7971f3e3dec37474490.tar.bz2 |
Address XXX comment in dis.py: inspect.py now attempts to reuse the dis.py compiler flag values before resorting to defining its own
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 61c2502..f894da2 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -36,15 +36,25 @@ import types import itertools import string import re -import dis import imp import tokenize import linecache from operator import attrgetter from collections import namedtuple -# These constants are from Include/code.h. -CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 0x1, 0x2, 0x4, 0x8 -CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40 + +# Create constants for the compiler flags in Include/code.h +# We try to get them from dis to avoid duplication, but fall +# back to hardcording so the dependency is optional +try: + from dis import COMPILER_FLAG_NAMES as _flag_names +except ImportError: + CO_OPTIMIZED, CO_NEWLOCALS = 0x1, 0x2 + CO_VARARGS, CO_VARKEYWORDS = 0x4, 0x8 + CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40 +else: + mod_dict = globals() + for k, v in _flag_names.items(): + mod_dict["CO_" + v] = k # See Include/object.h TPFLAGS_IS_ABSTRACT = 1 << 20 |