# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1534050202 -32400
#      Sun Aug 12 14:03:22 2018 +0900
# Node ID 6ee5e64e124c87b356874367dbf6355707d00883
# Parent  1c137e0a33afe4d7e61325513d2518af8b93434a
byteify-strings: prevent "__name__ == '__main__'" from being transformed

This was okay for import-time code transformer, but shouldn't be applied to
source code.

diff --git a/contrib/byteify-strings.py b/contrib/byteify-strings.py
--- a/contrib/byteify-strings.py
+++ b/contrib/byteify-strings.py
@@ -169,6 +169,11 @@ def replacetokens(tokens, opts):
                 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)
 
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to