changeset 39103:da130c5cef90

byteify-strings: prevent "__name__ == '__main__'" from being transformed This was okay for import-time code transformer, but shouldn't be applied to source code.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 12 Aug 2018 14:03:22 +0900
parents 08b2ae9fc030
children 2e578eced958
files contrib/byteify-strings.py
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/byteify-strings.py	Wed Aug 15 17:06:12 2018 -0400
+++ b/contrib/byteify-strings.py	Sun Aug 12 14:03:22 2018 +0900
@@ -169,6 +169,11 @@
                 yield adjusttokenpos(t._replace(string=fn[4:]), coloffset)
                 continue
 
+        # Looks like "if __name__ == '__main__'".
+        if (t.type == token.NAME and t.string == '__name__'
+            and _isop(i + 1, '==')):
+            _ensuresysstr(i + 2)
+
         # Emit unmodified token.
         yield adjusttokenpos(t, coloffset)