[New-bugs-announce] [issue20589] pathlib.owner() and pathlib.group() raise ImportError on Windows

James Skinner report at bugs.python.org
Tue Feb 11 04:25:09 CET 2014


New submission from James Skinner:

When using the Path class in Lib/pathlib.py under Windows, calling p.owner() or p.group() fails with an ImportError due to importing the pwd and grp modules respectively, as neither of those exist. The documentation doesn't mention this behaviour.

The precedent for handling this is set by os.stat(), which simply sets the st_uid and st_gid fields to 0 under Windows, and this behaviour underlies p.stat(). Therefore both p.owner() and p.group() should return 0 under Windows as well.

>>> p = Path("foo.py")
>>> p.stat()
os.stat_result(st_mode=33206, st_ino=434125405408, st_dev=318314347, st_nlink=1, st_uid=0, st_gid=0, st_size=40, st_atime=1392076800, st_mtime=1392084010, st_ctime=1392083969)
>>> p.owner()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python34\Lib\pathlib.py", line 1051, in owner
    import pwd
ImportError: No module named 'pwd'
>>> p.group()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python34\Lib\pathlib.py", line 1058, in group
    import grp
ImportError: No module named 'grp'

After the patch, the behaviour is:

>>> p = Path("foo.py")
>>> p.stat()
os.stat_result(st_mode=33206, st_ino=434125405408, st_dev=318314347, st_nlink=1, st_uid=0, st_gid=0, st_size=40, st_atime=1392076800, st_mtime=1392084010, st_ctime=1392083969)
>>> p.owner()
0
>>> p.group()
0
>>> p.owner() == p.stat().st_uid
True
>>> p.group() == p.stat().st_gid
True

The supplied patch just creates overriden versions of owner() and group() that return 0 under the WindowsPath class.

----------
components: Library (Lib)
files: win_owner_group_error_fix.patch
keywords: patch
messages: 210896
nosy: spiralx
priority: normal
severity: normal
status: open
title: pathlib.owner() and pathlib.group() raise ImportError on Windows
versions: Python 3.4
Added file: http://bugs.python.org/file34033/win_owner_group_error_fix.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20589>
_______________________________________


More information about the New-bugs-announce mailing list