[Python-checkins] peps: PEP 511: reformat to send by email
victor.stinner
python-checkins at python.org
Fri Jan 15 11:12:37 EST 2016
https://hg.python.org/peps/rev/4dca70ef4b97
changeset: 6191:4dca70ef4b97
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Jan 15 17:12:31 2016 +0100
summary:
PEP 511: reformat to send by email
files:
pep-0511.txt | 34 ++++++++++++++++------------------
1 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/pep-0511.txt b/pep-0511.txt
--- a/pep-0511.txt
+++ b/pep-0511.txt
@@ -32,8 +32,8 @@
hook a code transformer.
Python 3.4 added a ``compile_source()`` method to
-``importlib.abc.SourceLoader``. But code transformation is wider than just
-importing modules, see described use cases below.
+``importlib.abc.SourceLoader``. But code transformation is wider than
+just importing modules, see described use cases below.
Writing an optimizer or a preprocessor is out of the scope of this PEP.
@@ -104,8 +104,8 @@
Some examples:
-* Remove debug code like assertions and logs to make the code faster to run
- it for production.
+* Remove debug code like assertions and logs to make the code faster to
+ run it for production.
* `Tail-call Optimization <https://en.wikipedia.org/wiki/Tail_call>`_
* Add profiling code
* `Lazy evaluation <https://en.wikipedia.org/wiki/Lazy_evaluation>`_:
@@ -116,12 +116,13 @@
* Declare constants: see `@asconstants of codetransformer
<https://pypi.python.org/pypi/codetransformer>`_
* Domain Specific Language (DSL) like SQL queries. The
- Python language itself doesn't need to be modified. Previous attempts to
- implement DSL for SQL like `PEP 335 - Overloadable Boolean Operators
- <https://www.python.org/dev/peps/pep-0335/>`_ was rejected.
+ Python language itself doesn't need to be modified. Previous attempts
+ to implement DSL for SQL like `PEP 335 - Overloadable Boolean
+ Operators <https://www.python.org/dev/peps/pep-0335/>`_ was rejected.
* Pattern Matching of functional languages
* String Interpolation, but `PEP 498 -- Literal String Interpolation
- <https://www.python.org/dev/peps/pep-0498/>`_ was merged into Python 3.6.
+ <https://www.python.org/dev/peps/pep-0498/>`_ was merged into Python
+ 3.6.
`MacroPy <https://github.com/lihaoyi/macropy>`_ has a long list of
examples and use cases.
@@ -276,7 +277,8 @@
* *code*: the bytecode (``bytes``)
* *consts*: a sequence of constants
* *names*: tuple of variable names
-* *lnotab*: table mapping instruction offsets to line numbers (``bytes``)
+* *lnotab*: table mapping instruction offsets to line numbers
+ (``bytes``)
The code transformer is run after the compilation to bytecode
@@ -368,8 +370,9 @@
def transformers_tag():
transformers = sys.get_code_transformers()
if not transformers:
- return 'opt'
- return '-'.join(transformer.name for transformer in transformers)
+ return 'noopt'
+ return '-'.join(transformer.name
+ for transformer in transformers)
def use_py():
return (transformers_tag() == sys.implementation.optim_tag)
@@ -456,7 +459,6 @@
import sys
-
class BytecodeTransformer:
name = "knights_who_say_ni"
@@ -465,11 +467,10 @@
for const in consts]
return (code, consts, names, lnotab)
-
- # replace existing code transformers with our bytecode transformer
+ # replace existing code transformers with the new bytecode transformer
sys.set_code_transformers([BytecodeTransformer()])
- # execute code which will be transformed by ast_transformer()
+ # execute code which will be transformed by code_transformer()
exec("print('Hello World!')")
Output::
@@ -486,13 +487,11 @@
import ast
import sys
-
class KnightsWhoSayNi(ast.NodeTransformer):
def visit_Str(self, node):
node.s = 'Ni! Ni! Ni!'
return node
-
class ASTTransformer:
name = "knights_who_say_ni"
@@ -503,7 +502,6 @@
self.transformer.visit(tree)
return tree
-
# replace existing code transformers with the new AST transformer
sys.set_code_transformers([ASTTransformer()])
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list