5
5
import os
6
6
import re
7
7
import sys
8
+ import types
8
9
import typing as ty
9
10
10
11
from . import utils
@@ -511,7 +512,7 @@ def __init__(
511
512
#
512
513
# Note: `os.fwalk` support for binary paths was only added in 3.7+.
513
514
directory_str_or_fd = directory_str # type: ty.Union[ty.AnyStr, int]
514
- if HAVE_FWALK and (not isinstance (directory_str , bytes ) or HAVE_FWALK_BYTES ):
515
+ if HAVE_FWALK and (not isinstance (directory_str , bytes ) or HAVE_FWALK_BYTES ): # type: ignore[unreachable] # noqa: E501
515
516
self ._close_fd = directory_str_or_fd = os .open (directory_str , os .O_RDONLY | O_DIRECTORY )
516
517
517
518
self ._generator = self ._walk (
@@ -533,10 +534,24 @@ def __exit__(self, *a: ty.Any) -> None:
533
534
def send (self , value : ty .Any ) -> FSNodeEntry :
534
535
return self ._generator .send (value )
535
536
536
- def throw (self , typ : ty .Type [BaseException ], val : ty .Optional [BaseException ] = None ,
537
- tb : ty .Any = None ) -> FSNodeEntry :
537
+ @ty .overload
538
+ def throw (self , typ : ty .Type [BaseException ], # noqa: E704
539
+ val : ty .Union [BaseException , object ] = ...,
540
+ tb : ty .Optional [types .TracebackType ] = ...) -> FSNodeEntry : ...
541
+
542
+ @ty .overload
543
+ def throw (self , typ : BaseException , val : None = ..., # noqa: E704
544
+ tb : ty .Optional [types .TracebackType ] = ...) -> FSNodeEntry : ...
545
+
546
+ def throw (self , typ : ty .Union [ty .Type [BaseException ], BaseException ],
547
+ val : ty .Union [BaseException , object ] = None ,
548
+ tb : ty .Optional [types .TracebackType ] = None ) -> FSNodeEntry :
538
549
try :
539
- return self ._generator .throw (typ , val , tb )
550
+ if isinstance (typ , type ):
551
+ return self ._generator .throw (typ , val , tb )
552
+ else :
553
+ assert val is None
554
+ return self ._generator .throw (typ , val , tb )
540
555
except :
541
556
if self ._close_fd is not None :
542
557
os .close (self ._close_fd )
0 commit comments