Patchwork [2,of,9,V2] py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings

login
register
mail settings
Submitter Matt Harbison
Date Sept. 25, 2018, 2:25 a.m.
Message ID <bf1934083fa5c3a97492.1537842335@Envy>
Download mbox | patch
Permalink /patch/35002/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 25, 2018, 2:25 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537756604 14400
#      Sun Sep 23 22:36:44 2018 -0400
# Node ID bf1934083fa5c3a97492ea112ddb23e8ccf78294
# Parent  1fcff747a558e32f9cb9d8411c256532455c10f8
py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings

See also ac32685011a3.
Yuya Nishihara - Sept. 25, 2018, 12:38 p.m.
On Mon, 24 Sep 2018 22:25:35 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1537756604 14400
> #      Sun Sep 23 22:36:44 2018 -0400
> # Node ID bf1934083fa5c3a97492ea112ddb23e8ccf78294
> # Parent  1fcff747a558e32f9cb9d8411c256532455c10f8
> py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings

Queued the series, thanks.

> +    if pycompat.osname == b'nt':

Replaced this with pycompat.iswindows.

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -236,7 +236,12 @@  if not _nativeenviron:
 if pycompat.ispy3:
     # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
     # returns bytes.
-    getcwd = os.getcwdb  # re-exports
+    if pycompat.osname == b'nt':
+        # Python 3 on Windows issues a DeprecationWarning about using the bytes
+        # API when os.getcwdb() is called.
+        getcwd = lambda: strtolocal(os.getcwd())  # re-exports
+    else:
+        getcwd = os.getcwdb  # re-exports
 else:
     getcwd = os.getcwd  # re-exports