Commits

Jason R. Coombs committed a2ee8b5

As evidenced in pytest #245 (https://bitbucket.org/hpk42/pytest/issue/245), some file objects may not have a mode attribute. In this case, and if mode is not supplied, trap the AttributeError same as if f.fileno triggered an AttributeError.

  • Participants
  • Parent commits 31145a0

Comments (0)

Files changed (1)

py/_io/capture.py

     """
     try:
         fd = f.fileno()
+        mode = mode and mode or f.mode
     except AttributeError:
         if raising:
             raise
         return f
     newfd = os.dup(fd)
-    mode = mode and mode or f.mode
     if sys.version_info >= (3,0):
         if encoding is not None:
             mode = mode.replace("b", "")