From: Benjamin Peterson Date: Sun, 6 Mar 2011 23:14:30 +0000 (-0600) Subject: only do this sys.stderr replacing on CPython X-Git-Tag: v3.2.1b1~339^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d86e4c86733736f938100bae85b6eb3fadf5f02c;p=thirdparty%2FPython%2Fcpython.git only do this sys.stderr replacing on CPython --- diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py index e3ce24939db8..100232b61c0b 100644 --- a/Lib/lib2to3/pytree.py +++ b/Lib/lib2to3/pytree.py @@ -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 only have to do this on CPython, though, because other + # implementations don't have this nasty bug in the first place. + 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."""