New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.path.normcase(None) does not raise an error on linux and should #53264
Comments
os.path.normcase(None) raises an error on Windows but returns None on linux. os.path.abspath(None) raises an error in both cases. os.path.normcase(None) should raise an error on linux. I've only marked this for 3.2 because I suspect there may be linux code out there that this will break, so the fix should probably only be applied to 3.2. (I discovered this because a unit test someone else wrote passed on linux but failed on windows.) |
Right now posixpath returns the argument unchanged, ntpath performs a .replace(), and macpath a .lower(), so when non-string (or non-bytes) are passed to normcase the results are: In posixpath we could reject all the non-string (and non-bytes) args, raising a TypeError. For consistency, the other functions should raise a TypeError too, but I'm not sure it's worth changing it. Attached a simple testcase that checks that normcase raises a TypeError for invalid values with all the three implementations. |
It should be noticed that Linux-only code has absolutely no point in using normcase(), since it's a no-op there. |
Following the documentation, on Mac OS X,
>>> import os
>>> os.name
'posix' Checking through, Lib/posixpath.py, # Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. def normcase(s):
"""Normalize case of pathname. Has no effect under Posix"""
# TODO: on Mac OS X, this should really return s.lower().
return s Why on Mac OS X, it should return s.lower() ? def normcase(s):
"""Normalize case of pathname. Has no effect under Posix"""
if s is None:
raise AttributeError
return s |
On Sat, Jun 19, 2010 at 08:00:55PM +0000, Shashwat Anand wrote:
That is is because some file systems on Mac OS X are case-sensitive.
It should be a TypeError, not AttributeError. (Attached Test cases |
ntpath and macpath raise an AttributeError, so we could:
The option 2 is still an improvement over the current situation, but it would be better to find a backward-compatible way to also obtain option 1 (assuming that backward compatibility is a concern here -- and I think it is (even though people could just change the code to catch (AttributeError, TypeError) and eventually get rid of the AttributeError)). |
Sounds like the best thing to do.
This isn't an exception you catch at runtime. It's an exception you get |
Here is the patch. |
Nice patch. I like the use of new string formating. It can be applied. BTW, do you think that TODO of s.lower() for MAC OS X should be addressed along with this. It might require some research as how much of a desirable behavior it would be. |
My understanding is that there is a deep problem here, in that file system case (and in some cases encoding) is not OS/platform dependent, but is rather *file system* dependent. Adding lower to normcase on OS X is probably not going to break much code (he says with no evidence to back it up), but someday it would be nice to address the various file system type dependencies in the os module :( In any case, it is probably better to address the 'lower' issue in a separate issue/patch. |
Ah, I see my lack of knowledge of OS X has betrayed me. Apparently you can set the case sensitivity of OS X file systems....so the deep problem is even deeper than I thought :( |
This problem should be addressed in another issue though. |
Fixed in r82214. Now os.path.normcase() raises a TypeError if the arg is not str or bytes. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: