1212)
1313from fsspec .utils import stringify_path
1414
15- from upath .errors import NotDirectoryError
16-
1715
1816class _FSSpecAccessor :
1917 __slots__ = ("_fs" ,)
@@ -36,7 +34,17 @@ def stat(self, path, **kwargs):
3634 return self ._fs .stat (self ._format_path (path ), ** kwargs )
3735
3836 def listdir (self , path , ** kwargs ):
39- return self ._fs .listdir (self ._format_path (path ), ** kwargs )
37+ p_fmt = self ._format_path (path )
38+ contents = self ._fs .listdir (p_fmt , ** kwargs )
39+ if len (contents ) == 0 and not self ._fs .isdir (p_fmt ):
40+ raise NotADirectoryError
41+ elif (
42+ len (contents ) == 1
43+ and contents [0 ]["name" ] == p_fmt
44+ and contents [0 ]["type" ] == "file"
45+ ):
46+ raise NotADirectoryError
47+ return contents
4048
4149 def glob (self , _path , path_pattern , ** kwargs ):
4250 return self ._fs .glob (self ._format_path (path_pattern ), ** kwargs )
@@ -326,10 +334,8 @@ def rmdir(self, recursive=True):
326334 """Add warning if directory not empty
327335 assert is_dir?
328336 """
329- try :
330- assert self .is_dir ()
331- except AssertionError :
332- raise NotDirectoryError
337+ if not self .is_dir ():
338+ raise NotADirectoryError
333339 self ._accessor .rm (self , recursive = recursive )
334340
335341 def chmod (self , mode , * , follow_symlinks = True ):
0 commit comments