classification
Title: Introduce sys.implementation.opt_levels
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: 23731 Superseder:
Assigned To: Nosy List: brett.cannon, cheryl.sabella, eric.snow
Priority: low Keywords: patch

Created on 2015-04-08 21:41 by brett.cannon, last changed 2019-06-14 21:52 by eric.snow.

Pull Requests
URL Status Linked Edit
PR 9826 open cheryl.sabella, 2018-10-12 17:08
Messages (4)
msg240286 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-04-08 21:41
Eric suggested in a code review for issue #23731 that maybe we should have the possible optimization levels listed somewhere.
msg327601 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-10-12 17:14
Brett, I know you're away this month, so please ignore this,

Eric, I hope the changes I made reflect your original intent in the code review for #23731.


This is my first change to the C code, so I hope it's close.  The tests passed, so it must be correct.  ;-)  [j/k]
msg345636 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-06-14 20:41
(Sorry for taking so long!)

Thanks for doing this, Cheryl!  I'm leaving a review on your PR. :)

Also, in PEP 421 it says that you need a PEP for this. [1]  "Such a PEP need not be long, just long enough."  (I just realized that the requirement isn't obvious so I've opened issue #37284.)


[1] https://www.python.org/dev/peps/pep-0421/#adding-new-required-attributes
msg345641 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-06-14 21:52
There are (solvable) problems with my original recommendation:

1. sys.implementation is by definition not suitable for third-party import hooks to modify
  + it is set during the Python implementation during runtime init
  + it is effectively read-only after that
2. "opt_levels" is too specific to the CPython status quo
  + there are other ways to encode the optimizations of a bytecode file [1]
  + "optimizations" would probably be more correct
  + that opens a whole can of worms (e.g. what does sys.flags.optimize mean)

So we may want to think this over a bit before going any further.  I'm going to collect my thoughts on this and write more later. :)


[1] In PEP 488 it says:

    It is expected that beyond Python's own two optimization levels,
    third-party code will use a hash of optimization names to specify
    the optimization level, e.g. hashlib.sha256(','.join(['no dead code',
    'const folding'])).hexdigest().
History
Date User Action Args
2019-06-14 21:52:04eric.snowsetmessages: + msg345641
2019-06-14 20:41:30eric.snowsetmessages: + msg345636
versions: + Python 3.9, - Python 3.8
2018-10-12 17:14:32cheryl.sabellasetnosy: + cheryl.sabella

messages: + msg327601
versions: + Python 3.8, - Python 3.5
2018-10-12 17:08:55cheryl.sabellasetkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request9201
2015-04-08 21:41:58brett.cannonsetdependencies: + Implement PEP 488
title: Introduce sys.implementation.opt_levels ? -> Introduce sys.implementation.opt_levels
2015-04-08 21:41:44brett.cannoncreate