Patchwork [1,of,8,demandimport-py3] check-code: allow skipping hasattr check in py3-only code

login
register
mail settings
Submitter Siddharth Agarwal
Date May 21, 2017, 8:47 p.m.
Message ID <5e82c2bdd3331c097629.1495399676@devvm31800.prn1.facebook.com>
Download mbox | patch
Permalink /patch/20801/
State Accepted
Headers show

Comments

Siddharth Agarwal - May 21, 2017, 8:47 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1495398882 25200
#      Sun May 21 13:34:42 2017 -0700
# Node ID 5e82c2bdd3331c097629feb7108ec6b4975384e7
# Parent  c87db79b95079c3fd0032be7a25cd41567ed11cb
check-code: allow skipping hasattr check in py3-only code

hasattr is safe in Python 3, and in an upcoming patch we can't use
util.safehasattr.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -300,7 +300,8 @@  pypats = [
     (r'^\s*(while|if) [01]:',
      "use True/False for constant Boolean expression"),
     (r'(?:(?<!def)\s+|\()hasattr\(',
-     'hasattr(foo, bar) is broken, use util.safehasattr(foo, bar) instead'),
+     'hasattr(foo, bar) is broken on py2, use util.safehasattr(foo, bar) '
+     'instead', r'#.*hasattr-py3-only'),
     (r'opener\([^)]*\).read\(',
      "use opener.read() instead"),
     (r'opener\([^)]*\).write\(',