@@ -244,7 +244,7 @@ def __exit__(
244244 @property
245245 def buffer (self ) -> BinaryIO :
246246 # The str/bytes doesn't actually matter in this type, so OK to fake.
247- return self # type: ignore[return-value]
247+ return cast ( "BinaryIO" , self )
248248
249249
250250# Capture classes.
@@ -553,7 +553,7 @@ def snap(self) -> bytes:
553553 res = self .tmpfile .buffer .read ()
554554 self .tmpfile .seek (0 )
555555 self .tmpfile .truncate ()
556- return res # type: ignore[return-value]
556+ return cast ( "bytes" , res )
557557
558558 def writeorg (self , data : bytes ) -> None :
559559 """Write to original file descriptor."""
@@ -656,8 +656,10 @@ def pop_outerr_to_orig(self) -> tuple[AnyStr, AnyStr]:
656656 """Pop current snapshot out/err capture and flush to orig streams."""
657657 out , err = self .readouterr ()
658658 if out :
659+ assert self .out is not None
659660 self .out .writeorg (out ) # type: ignore[union-attr]
660661 if err :
662+ assert self .err is not None
661663 self .err .writeorg (err ) # type: ignore[union-attr]
662664 return out , err
663665
@@ -678,7 +680,8 @@ def resume_capturing(self) -> None:
678680 if self .err :
679681 self .err .resume ()
680682 if self ._in_suspended :
681- self .in_ .resume () # type: ignore[union-attr]
683+ assert self .in_ is not None
684+ self .in_ .resume ()
682685 self ._in_suspended = False
683686
684687 def stop_capturing (self ) -> None :
@@ -699,10 +702,9 @@ def is_started(self) -> bool:
699702 return self ._state == "started"
700703
701704 def readouterr (self ) -> CaptureResult [AnyStr ]:
702- out = self .out .snap () if self .out else ""
703- err = self .err .snap () if self .err else ""
704- # Will be fixed by pytest. This type error is real, need to fix.
705- return CaptureResult (out , err ) # type: ignore[arg-type]
705+ out = self .out .snap () if self .out else cast ("AnyStr" , "" )
706+ err = self .err .snap () if self .err else cast ("AnyStr" , "" )
707+ return CaptureResult (out , err )
706708
707709
708710def _get_multicapture (method : CaptureMethod ) -> MultiCapture [str ]:
0 commit comments