[PATCH 1 of 3] py3: add "b" prefix to string literals related to module policy

Yuya Nishihara yuya at tcha.org
Sun Mar 12 11:49:12 EDT 2017


On Sun, 12 Mar 2017 15:47:58 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1489300798 -32400
> #      Sun Mar 12 15:39:58 2017 +0900
> # Node ID 0f3cdc6061dc630d154c3fa45dfc8257d8ed9d09
> # Parent  62939e0148f170b67ca8c7374f36c413b67fd387
> py3: add "b" prefix to string literals related to module policy

> --- a/mercurial/policy.py
> +++ b/mercurial/policy.py
> @@ -20,8 +20,8 @@ import sys
>  #
>  # By default, require the C extensions for performance reasons.
>  policy = 'c'
> -policynoc = ('cffi', 'cffi-allow', 'py')
> -policynocffi = ('c', 'py')
> +policynoc = (b'cffi', b'cffi-allow', b'py')
> +policynocffi = (b'c', b'py')
>  
>  try:
>      from . import __modulepolicy__
> @@ -39,7 +39,11 @@ if '__pypy__' in sys.builtin_module_name
>  # Our C extensions aren't yet compatible with Python 3. So use pure Python
>  # on Python 3 for now.
>  if sys.version_info[0] >= 3:
> -    policy = b'py'
> +    policy = 'py'
>  
>  # Environment variable can always force settings.
>  policy = os.environ.get('HGMODULEPOLICY', policy)
> +
> +if sys.version_info[0] >= 3:
> +    # at this point, "policy" is still unicode
> +    policy = policy.encode('utf-8')

__modulepolicy__.modulepolicy is a bytes constant. I prefer keeping policy
always bytes so nobody would be tricked by bytes/unicode difference in future.


More information about the Mercurial-devel mailing list