MCPcopy Index your code
hub / github.com/python/cpython / _basename

Function _basename

Lib/shutil.py:858–874  ·  view source on GitHub ↗

A basename() variant which first strips the trailing slash, if present. Thus we always get the last component of the path, even for directories. path: Union[PathLike, str] e.g. >>> os.path.basename('/bar/foo') 'foo' >>> os.path.basename('/bar/foo/') '' >>> _basename

(path)

Source from the content-addressed store, hash-verified

856rmtree.avoids_symlink_attacks = _use_fd_functions
857
858def _basename(path):
859 """A basename() variant which first strips the trailing slash, if present.
860 Thus we always get the last component of the path, even for directories.
861
862 path: Union[PathLike, str]
863
864 e.g.
865 >>> os.path.basename('/bar/foo')
866 'foo'
867 >>> os.path.basename('/bar/foo/')
868 ''
869 >>> _basename('/bar/foo/')
870 'foo'
871 """
872 path = os.fspath(path)
873 sep = os.path.sep + (os.path.altsep or '')
874 return os.path.basename(path.rstrip(sep))
875
876def move(src, dst, copy_function=copy2):
877 """Recursively move a file or directory to another location. This is

Callers 1

moveFunction · 0.85

Calls 2

basenameMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…