classification
Title: isinstance checks in os.path.normcase redundant with os.fspath
Type: performance Stage: patch review
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, miss-islington, serhiy.storchaka, wolma
Priority: normal Keywords:

Created on 2017-05-22 08:17 by wolma, last changed 2019-03-28 21:47 by miss-islington.

Pull Requests
URL Status Linked Edit
PR 1712 merged wolma, 2017-05-22 08:27
Messages (5)
msg294130 - (view) Author: Wolfgang Maier (wolma) * Date: 2017-05-22 08:17
os.path.normcase as defined in both posixpath and ntpath is now calling os.fspath on its argument first. With that I think the following isinstance(str, bytes) checks have become redundant since AFAIU os.fspath is guaranteed to return either str or bytes instances.
msg294131 - (view) Author: Wolfgang Maier (wolma) * Date: 2017-05-22 08:31
Just created a PR for this, which eliminates the redundancy. This also changes the error message (making it less specific), but not the type of a raised exception.
If you think that the error message deserves to be preserved that could, of course, be done too.
msg294137 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-22 09:54
Does calling os.fspath() needed in normcase() at all? Is normcase() even called with arguments which are not just str/bytes?
msg294206 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-05-23 00:13
The problem with leaving os.fspath() out of os.path.normcase() is that suddenly a single function that deals with paths won't work with path-like objects. So that means support for path-like objects won't implicitly work in code that assumes a path but doesn't explicitly go out of its way to support path-like objects.
msg339077 - (view) Author: miss-islington (miss-islington) Date: 2019-03-28 21:47
New changeset 74510e2a57f6d4b51ac1ab4f778cd7a4c54b541e by Miss Islington (bot) (Wolfgang Maier) in branch 'master':
bpo-30427: eliminate redundant type checks in os.path.normcase() (GH-1712)
https://github.com/python/cpython/commit/74510e2a57f6d4b51ac1ab4f778cd7a4c54b541e
History
Date User Action Args
2019-03-28 21:47:27miss-islingtonsetnosy: + miss-islington
messages: + msg339077
2017-05-23 00:13:03brett.cannonsetmessages: + msg294206
2017-05-22 09:54:46serhiy.storchakasetnosy: + brett.cannon, serhiy.storchaka

messages: + msg294137
stage: patch review
2017-05-22 08:31:23wolmasettype: performance
messages: + msg294131
2017-05-22 08:27:59wolmasetpull_requests: + pull_request1803
2017-05-22 08:17:57wolmacreate