#1108 closed defect (fixed)

os.path.abspath() sometimes returns str instead of unicode?

Reported by: zooko Owned by: zooko
Priority: major Milestone: 1.8.0
Component: code Version: 1.7.0
Keywords: unicode review-needed Cc:
Launchpad Bug:

Description

Python 2.7 just came out, and reading through the changes led me to:

http://bugs.python.org/issue3426

We use os.path.abspath() in a few places where its argument is unicode.

I also noticed:

http://bugs.python.org/issue5827

but we don't currently use os.path.normpath().

How come our unit tests don't show this problem happening to us?

Attachments (1)

abspath-and-unicode-basedirs.dpatch (32.4 KB) - added by davidsarah at 2010-07-22T00:35:25Z.
* util.fileutil, test.test_util: add abspath_expanduser_unicode function, to work around <http://bugs.python.org/issue3426>. util.encodingutil: add a convenience function argv_to_abspath. * Replace uses of os.path.abspath with abspath_expanduser_unicode where necessary. This makes basedir paths consistently represented as Unicode.

Download all attachments as: .zip

Change History (9)

comment:1 Changed at 2010-07-17T05:35:35Z by davidsarah

  • Milestone changed from undecided to 1.8.0
  • Owner changed from francois to davidsarah
  • Status changed from new to assigned

comment:2 Changed at 2010-07-17T05:35:47Z by davidsarah

  • Component changed from unknown to code

Changed at 2010-07-22T00:35:25Z by davidsarah

  • util.fileutil, test.test_util: add abspath_expanduser_unicode function, to work around <http://bugs.python.org/issue3426>. util.encodingutil: add a convenience function argv_to_abspath. * Replace uses of os.path.abspath with abspath_expanduser_unicode where necessary. This makes basedir paths consistently represented as Unicode.

comment:3 Changed at 2010-07-22T00:50:44Z by davidsarah

  • Keywords review-needed added

Our tests might not show this for any of the following reasons:

  • We don't test or support Unicode paths for basedirs, which account for most of our uses of os.path.abspath.
  • Our Unicode tests for the CLI are a bit patchy; they only test Unicode paths for some commands.
  • When running the test suite, the current directory is the _trial_temp directory, which is at an ASCII path even if the test creates files and subdirectories at non-ASCII paths.
  • The bug in os.path.abspath only occurs when none of the resulting path components come from the input string the input path is relative and the current directory path is non-ASCII.
  • Even when os.path.abspath returns a bytestring, it will often get coerced to a Unicode string (not necessarily the correct one!) by the default Python coercions.

Note that while attachment:abspath-and-unicode-basedirs.dpatch makes most of the changes needed to support Unicode paths for basedirs, you still can't, at least on Windows, build or test a Tahoe source tree at an arbitrary Unicode path. (That would require changes to Python, darcs, setuptools, Twisted trial, etc., and is probably not a realistic aim.)

Last edited at 2010-07-22T00:54:13Z by davidsarah (previous) (diff)

comment:4 Changed at 2010-07-23T05:44:06Z by zooko

  • Owner changed from davidsarah to nobody
  • Status changed from assigned to new

comment:5 Changed at 2010-08-02T01:31:34Z by davidsarah

  • Owner changed from nobody to zooko

The changesets relevant to this ticket on the ticket798 branch are: [4598/ticket798] [4599/ticket798] [4601/ticket798] [4604/ticket798] [4606/ticket798] [4607/ticket798]

comment:7 Changed at 2010-08-14T06:55:33Z by zooko

  • Status changed from new to assigned

comment:8 Changed at 2010-09-10T19:28:31Z by zooko

  • Resolution set to fixed
  • Status changed from assigned to closed

Okay I looked over these patches a bit and didn't see anything obviously wrong. It was a pretty quick and lazy review, but better than nothing.

Note: See TracTickets for help on using tickets.