changeset 32184:cf424dae5dc7

check-code: ignore re-exports of os.environ in encoding.py These are valid uses of os.environ.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 01 May 2017 17:23:48 +0900
parents 41d79475d440
children 76f9a0009b4b
files contrib/check-code.py mercurial/encoding.py tests/test-check-code.t
diffstat 3 files changed, 5 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Wed Apr 26 21:51:19 2017 +0900
+++ b/contrib/check-code.py	Mon May 01 17:23:48 2017 +0900
@@ -474,7 +474,7 @@
 
 py3pats = [
   [
-    (r'os\.environ', "use encoding.environ instead (py3)"),
+    (r'os\.environ', "use encoding.environ instead (py3)", r'#.*re-exports'),
     (r'os\.name', "use pycompat.osname instead (py3)"),
     (r'os\.getcwd', "use pycompat.getcwd instead (py3)"),
     (r'os\.sep', "use pycompat.ossep instead (py3)"),
--- a/mercurial/encoding.py	Wed Apr 26 21:51:19 2017 +0900
+++ b/mercurial/encoding.py	Mon May 01 17:23:48 2017 +0900
@@ -51,14 +51,14 @@
 # the process environment
 _nativeenviron = (not pycompat.ispy3 or os.supports_bytes_environ)
 if not pycompat.ispy3:
-    environ = os.environ
+    environ = os.environ  # re-exports
 elif _nativeenviron:
-    environ = os.environb
+    environ = os.environb  # re-exports
 else:
     # preferred encoding isn't known yet; use utf-8 to avoid unicode error
     # and recreate it once encoding is settled
     environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8'))
-                   for k, v in os.environ.items())
+                   for k, v in os.environ.items())  # re-exports
 
 def _getpreferredencoding():
     '''
@@ -218,7 +218,7 @@
     # now encoding and helper functions are available, recreate the environ
     # dict to be exported to other modules
     environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8')))
-                   for k, v in os.environ.items())
+                   for k, v in os.environ.items())  # re-exports
 
 # How to treat ambiguous-width characters. Set to 'wide' to treat as wide.
 wide = (environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide"
--- a/tests/test-check-code.t	Wed Apr 26 21:51:19 2017 +0900
+++ b/tests/test-check-code.t	Mon May 01 17:23:48 2017 +0900
@@ -13,18 +13,6 @@
    >             r.revision(r.node(x))
    don't convert rev to node before passing to revision(nodeorrev)
   Skipping i18n/polib.py it has no-che?k-code (glob)
-  mercurial/encoding.py:54:
-   >     environ = os.environ
-   use encoding.environ instead (py3)
-  mercurial/encoding.py:56:
-   >     environ = os.environb
-   use encoding.environ instead (py3)
-  mercurial/encoding.py:61:
-   >                    for k, v in os.environ.items())
-   use encoding.environ instead (py3)
-  mercurial/encoding.py:221:
-   >                    for k, v in os.environ.items())
-   use encoding.environ instead (py3)
   Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)
   Skipping mercurial/httpclient/_readers.py it has no-che?k-code (glob)
   Skipping mercurial/statprof.py it has no-che?k-code (glob)