You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a problem if working with code which expects all strings to be
unicode strings (sometimes, functions raise exceptions if given a str,
when expecting a unicode).
I have attached patches (with test cases) for posixpath and ntpath which
correctly preserve the unicode-ness of the input string, such that the
new behaviour is:
I tried it on os2emxpath and plat-riscos/riscospath (the other two
OS-specific path modules), and it already worked fine for them.
Therefore, this patch fixes all necessary OS-specific versions of os.path.
Thanks for the patch, I tried it on Linux and it seems to solve the problem.
A few comments about it:
I'd change all the self.assertEqual(type(posixpath.normpath(u"")),
unicode) to self.assertTrue(isinstance(posixpath.normpath(u""), unicode));
a test for normpath(u'.') should probably be added;
in ntpath.py the 'slash' is actually a backslash, so the name of the
var should be changed;
mgiuca commented on Nov 19, 2009
mgiucamannequin
MannequinAuthor
More actions
Thanks Ezio.
I've updated the patch to incorporate your suggestions.
Note that I too have only tested it on Linux, but I tested both
posixpath and ntpath (and there is no OS-specific code, except for the
filenames themselves).
I'm not sure if using assertTrue(isinstance ...) is better than
assertEqual(type ...), because the type equality checking produces this
error:
AssertionError: <type 'str'> != <type 'unicode'>
while isinstance produces this unhelpful error:
AssertionError: False is not True
But oh well, I made the change anyway as most test cases use isinstance.
assertTrue() also accepts a 'msg' argument where to explain what went
wrong in case of failure 1.
sandberg commented on Nov 19, 2009
sandbergmannequin
Mannequin
More actions
Also, assertTrue has an alias failUnless which I personally find more
descriptive (I don't know if either form is preferred for inclusion in
Python though).
Activity
mgiuca commentedon Apr 24, 2009
In the Python 2.x branch, os.path.normpath will sometimes return a str
even if given a unicode. This is not an issue in the Python 3.0 branch.
This happens specifically when it throws away all string data and
constructs its own:
This is a problem if working with code which expects all strings to be
unicode strings (sometimes, functions raise exceptions if given a str,
when expecting a unicode).
I have attached patches (with test cases) for posixpath and ntpath which
correctly preserve the unicode-ness of the input string, such that the
new behaviour is:
I tried it on os2emxpath and plat-riscos/riscospath (the other two
OS-specific path modules), and it already worked fine for them.
Therefore, this patch fixes all necessary OS-specific versions of os.path.
ezio-melotti commentedon Nov 14, 2009
Thanks for the patch, I tried it on Linux and it seems to solve the problem.
A few comments about it:
unicode) to self.assertTrue(isinstance(posixpath.normpath(u""), unicode));
var should be changed;
mgiuca commentedon Nov 19, 2009
Thanks Ezio.
I've updated the patch to incorporate your suggestions.
Note that I too have only tested it on Linux, but I tested both
posixpath and ntpath (and there is no OS-specific code, except for the
filenames themselves).
I'm not sure if using assertTrue(isinstance ...) is better than
assertEqual(type ...), because the type equality checking produces this
error:
AssertionError: <type 'str'> != <type 'unicode'>
while isinstance produces this unhelpful error:
AssertionError: False is not True
But oh well, I made the change anyway as most test cases use isinstance.
ezio-melotti commentedon Nov 19, 2009
assertTrue() also accepts a 'msg' argument where to explain what went
wrong in case of failure 1.
sandberg commentedon Nov 19, 2009
Also, assertTrue has an alias failUnless which I personally find more
descriptive (I don't know if either form is preferred for inclusion in
Python though).
ezio-melotti commentedon Nov 19, 2009
failUnless is deprecated in Python3.1 1. The assert* methods are
preferred over the fail* ones that are now deprecated.
ezio-melotti commentedon Jan 12, 2010
Fixed in r77442 (trunk) and r77443 (release26-maint), thanks!