Patchwork test: make check-py3-compat.py ignore empty code more reliably

login
register
mail settings
Submitter Yuya Nishihara
Date March 11, 2016, 3:09 p.m.
Message ID <98e7cb1e1f3a4096e2b7.1457708973@mimosa>
Download mbox | patch
Permalink /patch/13786/
State Accepted
Headers show

Comments

Yuya Nishihara - March 11, 2016, 3:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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".
Pierre-Yves David - March 11, 2016, 3:24 p.m.
On 03/11/2016 03:09 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@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

This is pushed to the clowncopter, thanks

Patch

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):