[Python-Dev] [Python-checkins] cpython (2.6): #14984: only import pwd on POSIX.
R. David Murray
rdmurray at bitdance.com
Thu Sep 19 06:09:30 CEST 2013
On Wed, 18 Sep 2013 21:38:48 -0400, Barry Warsaw <barry at python.org> wrote:
> On Sep 18, 2013, at 03:00 PM, r.david.murray wrote:
>
> >http://hg.python.org/cpython/rev/fb3ad8a749c8
> >changeset: 85749:fb3ad8a749c8
> >branch: 2.6
> >parent: 85735:1b673e0fd8f3
> >user: R David Murray <rdmurray at bitdance.com>
> >date: Wed Sep 18 08:49:25 2013 -0400
> >summary:
> > #14984: only import pwd on POSIX.
> >
> >files:
> > Lib/netrc.py | 4 +++-
> > 1 files changed, 3 insertions(+), 1 deletions(-)
> >
> >
> >diff --git a/Lib/netrc.py b/Lib/netrc.py
> >--- a/Lib/netrc.py
> >+++ b/Lib/netrc.py
> >@@ -2,7 +2,9 @@
> >
> > # Module and documentation by Eric S. Raymond, 21 Dec 1998
> >
> >-import os, stat, shlex, pwd
> >+import os, stat, shlex
> >+if os.name == 'posix':
> >+ import pwd
>
> Would it make more sense to do:
>
> try:
> import pwd
> except ImportError:
> pwd = None
I don't think so. The code that uses pwd is protected by an 'if os.name
== 'posix' as well. I think that's clearer than setting pwd to none
and guarding that section by 'if pwd'. And in 3.4 I just moved the
import into the if block that uses it.
--David
More information about the Python-Dev
mailing list