Patchwork [1,of,2] pycompat: when setting attrs, ensure we use sysstr

login
register
mail settings
Submitter Augie Fackler
Date Oct. 8, 2016, 12:40 p.m.
Message ID <53708ce020c58f25079e.1475930406@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/16918/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 8, 2016, 12:40 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1475930143 14400
#      Sat Oct 08 08:35:43 2016 -0400
# Node ID 53708ce020c58f25079ef7b3802c71308843c0b4
# Parent  392dc40e200e6fdc3ee5172c949b81cc56163e62
pycompat: when setting attrs, ensure we use sysstr

The custom module importer was making these bytes, so when we poked
values into self.__dict__ we had bytes instead of unicode on py3 and
it didn't work.
Martijn Pieters - Oct. 8, 2016, 3:08 p.m.
On 8 October 2016 at 14:40, Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1475930143 14400
> #      Sat Oct 08 08:35:43 2016 -0400
> # Node ID 53708ce020c58f25079ef7b3802c71308843c0b4
> # Parent  392dc40e200e6fdc3ee5172c949b81cc56163e62
> pycompat: when setting attrs, ensure we use sysstr
>
> The custom module importer was making these bytes, so when we poked
> values into self.__dict__ we had bytes instead of unicode on py3 and
> it didn't work.
>

Looks great.



>
> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
> --- a/mercurial/pycompat.py
> +++ b/mercurial/pycompat.py
> @@ -74,8 +74,10 @@ class _pycompatstub(object):
>
>      def _registeraliases(self, origin, items):
>          """Add items that will be populated at the first access"""
> -        self._aliases.update((item.replace('_', '').lower(), (origin,
> item))
> -                             for item in items)
> +        items = map(sysstr, items)
> +        self._aliases.update(
> +            (item.replace(sysstr('_'), sysstr('')).lower(), (origin,
> item))
> +            for item in items)
>
>      def __getattr__(self, name):
>          try:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -74,8 +74,10 @@  class _pycompatstub(object):
 
     def _registeraliases(self, origin, items):
         """Add items that will be populated at the first access"""
-        self._aliases.update((item.replace('_', '').lower(), (origin, item))
-                             for item in items)
+        items = map(sysstr, items)
+        self._aliases.update(
+            (item.replace(sysstr('_'), sysstr('')).lower(), (origin, item))
+            for item in items)
 
     def __getattr__(self, name):
         try: