[PATCH 01 of 10] py3: use unicode literals in encoding.py

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Aug 5 12:15:35 EDT 2016


At Fri, 5 Aug 2016 23:23:39 +0900,
Yuya Nishihara wrote:
> 
> On Fri, 05 Aug 2016 08:16:50 +0900, FUJIWARA Katsunori wrote:
> > At Thu, 4 Aug 2016 21:42:22 +0900,
> > Yuya Nishihara wrote:
> > > 
> > > On Thu, 04 Aug 2016 00:18:19 +0900, FUJIWARA Katsunori wrote:
> > > > If (almost) all of operations with string literal in target source
> > > > code requires unicode-ness on Python 3.x, this omitting can reduce
> > > > adding explicit 'u' prefix to existing string literals.
> > > > 
> > > > For example, all operations with string literal in demandimport.py are
> > > > related to APIs below, which accept only unicode (as str) on Python
> > > > 3.x.
> > > > 
> > > >   - manipulate module name
> > > >     split(), formatting with "%s", __contains__(), and so on
> > > >   - access to attributes by name
> > > >   - access to values in os.environ
> > > >   - access to values in sys.builtin_module_names
> > > > 
> > > > pycompat.py and i18n.py also seem to work with this omitting. At short
> > > > glance, maybe, pure/osutil.py does, too ? (a few extra explicit 'b'
> > > > prefix might be needed, though)
> > > 
> > > i18n.setdatapath() would need b'locale', and pure.osutil.posixfile() would
> > > need b'r', b'w', etc. because u'r' != b'r' on Python 3.
> > 
> > I think that 'locale' in i18n.setdatapath() should be 'str' of Python
> > at runtime because:
> > 
> >   (1) i18n.setdatapath() is invoked with os.path.dirname()-ed one of
> >       below in util.py:
> > 
> >       - sys.executable => str
> >       - __file__ => str
> > 
> >   (2) os.path.join() doesn't accept u'' and b'' at once on Python 3.x,
> >       as mentioned in 02/10 of this series
> 
> Since both i18n.setdatapath() and util.datapath are public, they should be
> bytes-API. Otherwise, we would have to remember which function/constant is
> which.
> 

Oh, I overlooked that util.datapath is used also by other than
invocation of i18n.setdatapath(). Thank you for pointing it out!

Then, for consistency, we should add the code to ensure bytes-ness of
datapath in util.py before changing i18n.setdatapath(), shouldn't we ?

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list