Nick Coghlan added the comment:

Bringing a design discussion back from the code review, since I didn't explain 
the problem to be solved very well, and instead jumped straight to recommending 
a specific solution.

Currently, dis has a dictionary mapping from hardcoded compiler flag values (in 
decimal, no less!) to flag names. The inspect module then iterates over this 
dictionary at import time to publish the CO_* constants as module level 
attributes in inspect.

Neither dis.COMPILER_FLAG_NAMES nor the inspect.CO_* constants are documented, 
and the *C* level flag values aren't published to the Python layer anywhere 
(hence the hardcoding of the magic numbers in dis).

For the kind of code that needs to interrogate the flags in the issue 24400 
patch, inspect and dis are also not appropriate things to adopt as dependencies.

However, I like Larry's suggestion of adopting the _opcode module as our 
standard vector for passing this information up from the C layer to the Python 
layer better than my original idea of using code objects themselves.

The opcode values themselves could potentially also be exposed that way 
(they're currently duplicated by hand in Lib/

title: Expose compiler flag constants as code object attributes -> Expose C 
level compiler flag constants to Python code

Python tracker <>
Python-bugs-list mailing list

Reply via email to