This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2017-05-22 08:17 by wolma, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1712 merged wolma, 2017-05-22 08:27
Messages (7)
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)
msg358868 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-25 15:40
Looks like there is nothing left after PR 1712 if I am not missing something, can this issue be closed?
msg359223 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-01-02 22:13
Yep, it looks like this is fixed, Batuhan. Thanks for letting us know!
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74612
2020-01-02 22:13:44brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg359223

stage: patch review -> resolved
2019-12-25 15:40:39BTaskayasetnosy: + BTaskaya
messages: + msg358868
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