summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>2019-03-28 22:47:18 +0100
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-03-28 14:47:18 -0700
commit74510e2a57f6d4b51ac1ab4f778cd7a4c54b541e (patch)
tree438bf203d740c30bd870b014dfab1748964352c4
parent02b84cb1b4f5407309c81c8b1ae0397355d6e568 (diff)
downloadcpython-git-74510e2a57f6d4b51ac1ab4f778cd7a4c54b541e.tar.gz
bpo-30427: eliminate redundant type checks in os.path.normcase() (GH-1712)
https://bugs.python.org/issue30427
-rw-r--r--Lib/ntpath.py14
-rw-r--r--Lib/posixpath.py6
-rw-r--r--Misc/NEWS.d/next/Library/2019-03-28-21-17-08.bpo-30427.lxzvbw.rst2
3 files changed, 7 insertions, 15 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index b5e1d121fc..f3cfabf023 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -46,16 +46,10 @@ def normcase(s):
Makes all characters lowercase and all slashes into backslashes."""
s = os.fspath(s)
- try:
- if isinstance(s, bytes):
- return s.replace(b'/', b'\\').lower()
- else:
- 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
+ if isinstance(s, bytes):
+ return s.replace(b'/', b'\\').lower()
+ else:
+ return s.replace('/', '\\').lower()
# Return whether a path is absolute.
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 12ab2eadbf..21ce72fd79 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -51,11 +51,7 @@ def _get_sep(path):
def normcase(s):
"""Normalize case of pathname. Has no effect under Posix"""
- s = 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 os.fspath(s)
# Return whether a path is absolute.
diff --git a/Misc/NEWS.d/next/Library/2019-03-28-21-17-08.bpo-30427.lxzvbw.rst b/Misc/NEWS.d/next/Library/2019-03-28-21-17-08.bpo-30427.lxzvbw.rst
new file mode 100644
index 0000000000..80e7c4a15e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-28-21-17-08.bpo-30427.lxzvbw.rst
@@ -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.