Skip to content

Commit 74510e2

Browse files
Wolfgang Maiermiss-islington
Wolfgang Maier
authored andcommitted
bpo-30427: eliminate redundant type checks in os.path.normcase() (GH-1712)
https://bugs.python.org/issue30427
1 parent 02b84cb commit 74510e2

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

Lib/ntpath.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ def normcase(s):
4646
4747
Makes all characters lowercase and all slashes into backslashes."""
4848
s = os.fspath(s)
49-
try:
50-
if isinstance(s, bytes):
51-
return s.replace(b'/', b'\\').lower()
52-
else:
53-
return s.replace('/', '\\').lower()
54-
except (TypeError, AttributeError):
55-
if not isinstance(s, (bytes, str)):
56-
raise TypeError("normcase() argument must be str or bytes, "
57-
"not %r" % s.__class__.__name__) from None
58-
raise
49+
if isinstance(s, bytes):
50+
return s.replace(b'/', b'\\').lower()
51+
else:
52+
return s.replace('/', '\\').lower()
5953

6054

6155
# Return whether a path is absolute.

Lib/posixpath.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def _get_sep(path):
5151

5252
def normcase(s):
5353
"""Normalize case of pathname. Has no effect under Posix"""
54-
s = os.fspath(s)
55-
if not isinstance(s, (bytes, str)):
56-
raise TypeError("normcase() argument must be str or bytes, "
57-
"not '{}'".format(s.__class__.__name__))
58-
return s
54+
return os.fspath(s)
5955

6056

6157
# Return whether a path is absolute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``os.path.normcase()`` relies on ``os.fspath()`` to check the type of its argument. Redundant checks have been removed from its ``posixpath.normcase()`` and ``ntpath.normcase()`` implementations.
2+
Patch by Wolfgang Maier.

0 commit comments

Comments
 (0)