Skip to content

Commit 97eed0f

Browse files
sbc100kripken
authored andcommitted
Fix suffix() and unsuffix() to use python builtins (#4912)
* Fix suffix() and unsuffix() to use python builtins I ran into a strange behaviour with the existing custom implementation: unsuffix("foo.txt") -> "foo" unsuffix("foo") -> "" The python builtins to a seemingly more reasonable thing: unsuffix("foo.txt") -> "foo" unsuffix("foo") -> "foo" * Add myself to AUTHORS
1 parent abda378 commit 97eed0f

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,5 @@ a license to everyone to use it as detailed in LICENSE.)
273273
* Murphy McCauley <[email protected]>
274274
* Anatoly Trosinenko <[email protected]>
275275
* Brad Grantham <[email protected]>
276+
* Sam Clegg <[email protected]> (copyright owned by Google, Inc.)
276277

tools/shared.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,14 +2336,11 @@ def check_call(cmd, *args, **kw):
23362336
raise
23372337

23382338
def suffix(name):
2339-
parts = name.split('.')
2340-
if len(parts) > 1:
2341-
return parts[-1]
2342-
else:
2343-
return None
2339+
"""Return the file extension *not* including the '.'."""
2340+
return os.path.splitext(name)[1][1:]
23442341

23452342
def unsuffixed(name):
2346-
return '.'.join(name.split('.')[:-1])
2343+
return os.path.splitext(name)[0]
23472344

23482345
def unsuffixed_basename(name):
23492346
return os.path.basename(unsuffixed(name))

0 commit comments

Comments
 (0)