Submitter | Manuel Jacob |
---|---|
Date | June 16, 2020, 1:50 a.m. |
Message ID | <4771e5ae53c4d6fe4c4c.1592272230@tmp> |
Download | mbox | patch |
Permalink | /patch/46513/ |
State | Accepted |
Headers | show |
Comments
On Tue, 16 Jun 2020 03:50:30 +0200, Manuel Jacob wrote: > # HG changeset patch > # User Manuel Jacob <me@manueljacob.de> > # Date 1592185813 -7200 > # Mon Jun 15 03:50:13 2020 +0200 > # Branch stable > # Node ID 4771e5ae53c4d6fe4c4cc66497930f06c16e6179 > # Parent f86ca8753fb2a1c15c8abda7991181e09ad36071 > # EXP-Topic convert-svn > py3: ignore warning about deprecated `base64.encodestring()` > > It fixes the following warning: > hgext/convert/common.py:89: DeprecationWarning: encodestring() is a deprecated alias since 3.1, use encodebytes() > lines = base64.encodestring(s) > > `base64.encodebytes()` doesn’t exist on Python 2. Therefore, we continue to use > `base64.encodestring()`. > > An alternative way to get rid of this warning would have been to call > `base64.encodebytes()` if available, and `base64.encodestring()` otherwise. I prefer using `if py3` switch than suppressing the warning.
On 2020-06-16 11:47, Yuya Nishihara wrote: > On Tue, 16 Jun 2020 03:50:30 +0200, Manuel Jacob wrote: >> # HG changeset patch >> # User Manuel Jacob <me@manueljacob.de> >> # Date 1592185813 -7200 >> # Mon Jun 15 03:50:13 2020 +0200 >> # Branch stable >> # Node ID 4771e5ae53c4d6fe4c4cc66497930f06c16e6179 >> # Parent f86ca8753fb2a1c15c8abda7991181e09ad36071 >> # EXP-Topic convert-svn >> py3: ignore warning about deprecated `base64.encodestring()` >> >> It fixes the following warning: >> hgext/convert/common.py:89: DeprecationWarning: encodestring() is a >> deprecated alias since 3.1, use encodebytes() >> lines = base64.encodestring(s) >> >> `base64.encodebytes()` doesn’t exist on Python 2. Therefore, we >> continue to use >> `base64.encodestring()`. >> >> An alternative way to get rid of this warning would have been to call >> `base64.encodebytes()` if available, and `base64.encodestring()` >> otherwise. > > I prefer using `if py3` switch than suppressing the warning. My first attempt was to have the switch at the module level. Is this acceptable or is it problematic with lazy-loading?
On Tue, 16 Jun 2020 12:52:55 +0200, Manuel Jacob wrote: > On 2020-06-16 11:47, Yuya Nishihara wrote: > > On Tue, 16 Jun 2020 03:50:30 +0200, Manuel Jacob wrote: > >> # HG changeset patch > >> # User Manuel Jacob <me@manueljacob.de> > >> # Date 1592185813 -7200 > >> # Mon Jun 15 03:50:13 2020 +0200 > >> # Branch stable > >> # Node ID 4771e5ae53c4d6fe4c4cc66497930f06c16e6179 > >> # Parent f86ca8753fb2a1c15c8abda7991181e09ad36071 > >> # EXP-Topic convert-svn > >> py3: ignore warning about deprecated `base64.encodestring()` > >> > >> It fixes the following warning: > >> hgext/convert/common.py:89: DeprecationWarning: encodestring() is a > >> deprecated alias since 3.1, use encodebytes() > >> lines = base64.encodestring(s) > >> > >> `base64.encodebytes()` doesn’t exist on Python 2. Therefore, we > >> continue to use > >> `base64.encodestring()`. > >> > >> An alternative way to get rid of this warning would have been to call > >> `base64.encodebytes()` if available, and `base64.encodestring()` > >> otherwise. > > > > I prefer using `if py3` switch than suppressing the warning. > > My first attempt was to have the switch at the module level. Is this > acceptable or is it problematic with lazy-loading? I think module-level switch is fine as base64.py is small. If the loading cost really matters, the module function can be wrapped in a function. if py3: def _b64encode(s): return base64.encodebytes(s)
Patch
diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -191,6 +191,9 @@ DeprecationWarning, 'mercurial', ) + warnings.filterwarnings( + 'ignore', 'encodestring', DeprecationWarning, 'hgext' + ) def nouideprecwarn(msg, version, stacklevel=1):