]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
only do this sys.stderr replacing on CPython
authorBenjamin Peterson <benjamin@python.org>
Sun, 6 Mar 2011 23:08:40 +0000 (17:08 -0600)
committerBenjamin Peterson <benjamin@python.org>
Sun, 6 Mar 2011 23:08:40 +0000 (17:08 -0600)
Lib/lib2to3/pytree.py

index b24283e0eead78144326ab54b055270a819c81f0..c2fa80014a02ec9e3d7fe8f52589fc3b72ac36f0 100644 (file)
@@ -743,9 +743,11 @@ class WildcardPattern(BasePattern):
         else:
             # The reason for this is that hitting the recursion limit usually
             # results in some ugly messages about how RuntimeErrors are being
-            # ignored.
-            save_stderr = sys.stderr
-            sys.stderr = StringIO()
+            # ignored. We don't do this on non-CPython implementation because
+            # they don't have this problem.
+            if hasattr(sys, "getrefcount"):
+                save_stderr = sys.stderr
+                sys.stderr = StringIO()
             try:
                 for count, r in self._recursive_matches(nodes, 0):
                     if self.name:
@@ -759,7 +761,8 @@ class WildcardPattern(BasePattern):
                         r[self.name] = nodes[:count]
                     yield count, r
             finally:
-                sys.stderr = save_stderr
+                if hasattr(sys, "getrefcount"):
+                    sys.stderr = save_stderr
 
     def _iterative_matches(self, nodes):
         """Helper to iteratively yield the matches."""