[PATCH] test: make check-py3-compat.py ignore empty code more reliably

Yuya Nishihara yuya at tcha.org
Fri Mar 11 10:09:33 EST 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1457659618 -32400
#      Fri Mar 11 10:26:58 2016 +0900
# Node ID 98e7cb1e1f3a4096e2b7f122b43bfda5e7f775dc
# Parent  0902f40370d82ef53dd8997cf7b4cfee8e418c63
test: make check-py3-compat.py ignore empty code more reliably

It couldn't exclude an empty file containing comments. That's why
hgext/__init__.py had been listed in test-check-py3-compat.t before
"hgext: officially turn 'hgext' into a namespace package".

diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -16,12 +16,12 @@ def check_compat(f):
     """Check Python 3 compatibility for a file."""
     with open(f, 'rb') as fh:
         content = fh.read()
+    root = ast.parse(content)
 
     # Ignore empty files.
-    if not content.strip():
+    if not root.body:
         return
 
-    root = ast.parse(content)
     futures = set()
     haveprint = False
     for node in ast.walk(root):


More information about the Mercurial-devel mailing list