Author: Ronan Lamy <[email protected]>
Branch: __debug__-optimize
Changeset: r97081:b9c4efabfa18
Date: 2019-08-06 17:23 +0100
http://bitbucket.org/pypy/pypy/changeset/b9c4efabfa18/
Log: Constant-fold __debug__ at compile time
diff --git a/pypy/interpreter/astcompiler/optimize.py
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -73,8 +73,15 @@
def as_constant(self, space, compile_info):
return self.value
+class __extend__(ast.Name):
+ def as_constant(self, space, compile_info):
+ if self.id == '__debug__':
+ return space.newbool(compile_info.optimize == 0)
+ else:
+ return None
+
+
class __extend__(ast.NameConstant):
-
def as_constant(self, space, compile_info):
return self.value
@@ -271,8 +278,9 @@
if name.ctx == ast.Del:
return name
space = self.space
- iden = name.id
w_const = None
+ if name.id == '__debug__':
+ w_const = space.newbool(self.compile_info.optimize == 0)
if w_const is not None:
return ast.NameConstant(w_const, name.lineno, name.col_offset)
return name
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit