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

Method with_suffix

Lib/pathlib/__init__.py:430–442  ·  view source on GitHub ↗

Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.

(self, suffix)

Source from the content-addressed store, hash-verified

428 return self.with_name(stem + suffix)
429
430 def with_suffix(self, suffix):
431 """Return a new path with the file suffix changed. If the path
432 has no suffix, add given suffix. If the given suffix is an empty
433 string, remove the suffix from the path.
434 """
435 stem = self.stem
436 if not stem:
437 # If the stem is empty, we can't make the suffix non-empty.
438 raise ValueError(f"{self!r} has an empty name")
439 elif suffix and not suffix.startswith('.'):
440 raise ValueError(f"Invalid suffix {suffix!r}")
441 else:
442 return self.with_name(stem + suffix)
443
444 @property
445 def stem(self):

Callers 15

build_python_pathFunction · 0.45
build_python_pathFunction · 0.45
build_python_pathFunction · 0.45
build_python_pathFunction · 0.45
create_archiveFunction · 0.45
_path_to_moduleFunction · 0.45
test_cmdline_createMethod · 0.45
_compile_importlibMethod · 0.45
test_with_segmentsMethod · 0.45
test_with_suffixMethod · 0.45
test_with_suffixMethod · 0.45

Calls 2

with_nameMethod · 0.95
startswithMethod · 0.45

Tested by 10

test_cmdline_createMethod · 0.36
_compile_importlibMethod · 0.36
test_with_segmentsMethod · 0.36
test_with_suffixMethod · 0.36
test_with_suffixMethod · 0.36
test_bytesMethod · 0.36
test_walk_bad_dirMethod · 0.36
test_compilationMethod · 0.36
update_catalog_snapshotsFunction · 0.36
extract_from_snapshotsFunction · 0.36