Author vstinner
Recipients Solomon Ucko, Trundle, benjamin.peterson, eric.araujo, ezio.melotti, georg.brandl, python-dev, vstinner
Date 2019-03-07.11:38:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> The byte code could be further optimized (because this is such a speed-critical module! :)): (...)

You propose to replace

              8 CALL_FUNCTION            1
             10 POP_TOP
             12 LOAD_CONST               2 (None)
             14 RETURN_VALUE


             12 CALL_FUNCTION            1 
             15 RETURN_VALUE

It changes the semantics of Python. Technically, you *can* override the print() builtin function:

vstinner@apu$ ./python
Python 3.8.0a2+ (heads/master:dc078947a5, Mar  7 2019, 12:23:23) 
>>> import builtins
>>> def mock(*args, **kw): return 3
>>> builtins.print=mock
>>> print("hello")
>>> import __phello__
>>> # doesn't print anything

It would be possible if you ensure that print() isn't replaced.

Longer explanation:

To use more efficient bytecode without modying the Python semantics, you need to deoptimize if print() is replaced. I implemented that in my old FAT Python project :-)


I would be more interested by a tool to update/regenerate M___hello__ in Python/frozen.c.
Date User Action Args
2019-03-07 11:38:41vstinnersetrecipients: + vstinner, georg.brandl, benjamin.peterson, ezio.melotti, eric.araujo, Trundle, python-dev, Solomon Ucko
2019-03-07 11:38:41vstinnersetmessageid: <>
2019-03-07 11:38:41vstinnerlinkissue11614 messages
2019-03-07 11:38:41vstinnercreate