Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9c8d0e

Browse files
committed
merge 3.1
2 parents 63bd5f9 + d86e4c8 commit c9c8d0e

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Lib/lib2to3/pytree.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,11 @@ def generate_matches(self, nodes):
743743
else:
744744
# The reason for this is that hitting the recursion limit usually
745745
# results in some ugly messages about how RuntimeErrors are being
746-
# ignored.
747-
save_stderr = sys.stderr
748-
sys.stderr = StringIO()
746+
# ignored. We only have to do this on CPython, though, because other
747+
# implementations don't have this nasty bug in the first place.
748+
if hasattr(sys, "getrefcount"):
749+
save_stderr = sys.stderr
750+
sys.stderr = StringIO()
749751
try:
750752
for count, r in self._recursive_matches(nodes, 0):
751753
if self.name:
@@ -759,7 +761,8 @@ def generate_matches(self, nodes):
759761
r[self.name] = nodes[:count]
760762
yield count, r
761763
finally:
762-
sys.stderr = save_stderr
764+
if hasattr(sys, "getrefcount"):
765+
sys.stderr = save_stderr
763766

764767
def _iterative_matches(self, nodes):
765768
"""Helper to iteratively yield the matches."""

0 commit comments

Comments
 (0)