mirror of https://github.com/python/cpython.git
bpo-30427: eliminate redundant type checks in os.path.normcase() (GH-1712)
https://bugs.python.org/issue30427
This commit is contained in:
parent
02b84cb1b4
commit
74510e2a57
|
@ -46,16 +46,10 @@ def normcase(s):
|
||||||
|
|
||||||
Makes all characters lowercase and all slashes into backslashes."""
|
Makes all characters lowercase and all slashes into backslashes."""
|
||||||
s = os.fspath(s)
|
s = os.fspath(s)
|
||||||
try:
|
if isinstance(s, bytes):
|
||||||
if isinstance(s, bytes):
|
return s.replace(b'/', b'\\').lower()
|
||||||
return s.replace(b'/', b'\\').lower()
|
else:
|
||||||
else:
|
return s.replace('/', '\\').lower()
|
||||||
return s.replace('/', '\\').lower()
|
|
||||||
except (TypeError, AttributeError):
|
|
||||||
if not isinstance(s, (bytes, str)):
|
|
||||||
raise TypeError("normcase() argument must be str or bytes, "
|
|
||||||
"not %r" % s.__class__.__name__) from None
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
# Return whether a path is absolute.
|
# Return whether a path is absolute.
|
||||||
|
|
|
@ -51,11 +51,7 @@ def _get_sep(path):
|
||||||
|
|
||||||
def normcase(s):
|
def normcase(s):
|
||||||
"""Normalize case of pathname. Has no effect under Posix"""
|
"""Normalize case of pathname. Has no effect under Posix"""
|
||||||
s = os.fspath(s)
|
return os.fspath(s)
|
||||||
if not isinstance(s, (bytes, str)):
|
|
||||||
raise TypeError("normcase() argument must be str or bytes, "
|
|
||||||
"not '{}'".format(s.__class__.__name__))
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
# Return whether a path is absolute.
|
# Return whether a path is absolute.
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
``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.
|
||||||
|
Patch by Wolfgang Maier.
|
Loading…
Reference in New Issue