[libcxx-commits] [PATCH] D107715: [libc++][NFC] Resolve Python 2 FIXME

Alf via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 8 08:57:00 PDT 2021


gAlfonso-bit created this revision.
gAlfonso-bit added a reviewer: libc++.
gAlfonso-bit added projects: LLVM, libc++.
Herald added a subscriber: arichardson.
gAlfonso-bit requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

We don't use Python 2 anymore, so let us do the recommended fix instead of using the workaround made for Python 2.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107715

Files:
  libcxx/utils/libcxx/util.py


Index: libcxx/utils/libcxx/util.py
===================================================================
--- libcxx/utils/libcxx/util.py
+++ libcxx/utils/libcxx/util.py
@@ -102,7 +102,7 @@
     (or the PATH environment variable, if unspecified)."""
 
     if paths is None:
-        paths = os.environ.get('PATH','')
+        paths = os.environ.get('PATH', '')
 
     # Check for absolute match first.
     if os.path.isfile(command):
@@ -202,23 +202,21 @@
                          stderr=subprocess.PIPE,
                          env=env, close_fds=kUseCloseFDs)
     timerObject = None
-    # FIXME: Because of the way nested function scopes work in Python 2.x we
-    # need to use a reference to a mutable object rather than a plain
-    # bool. In Python 3 we could use the "nonlocal" keyword but we need
-    # to support Python 2 as well.
-    hitTimeOut = [False]
+
+    nonlocal hitTimeOut
+    hitTimeOut = False
     try:
         if timeout > 0:
             def killProcess():
                 # We may be invoking a shell so we need to kill the
                 # process and all its children.
-                hitTimeOut[0] = True
+                hitTimeOut = True
                 killProcessAndChildren(p.pid)
 
             timerObject = threading.Timer(timeout, killProcess)
             timerObject.start()
 
-        out,err = p.communicate(input=input)
+        out, err = p.communicate(input=input)
         exitCode = p.wait()
     finally:
         if timerObject != None:
@@ -228,7 +226,7 @@
     out = convert_string(out)
     err = convert_string(err)
 
-    if hitTimeOut[0]:
+    if hitTimeOut:
         raise ExecuteCommandTimeoutException(
             msg='Reached timeout of {} seconds'.format(timeout),
             out=out,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107715.365027.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210808/f84a0cdb/attachment-0001.bin>


More information about the libcxx-commits mailing list