Skip to content

Commit 5c81ed4

Browse files
bpo-31972: Improve docstrings for pathlib classes (GH-5310)
(cherry picked from commit dfa015c) Co-authored-by: chason <chason@gmail.com>
1 parent ea49c03 commit 5c81ed4

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lib/pathlib.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@ def __repr__(self):
600600

601601

602602
class PurePath(object):
603-
"""PurePath represents a filesystem path and offers operations which
603+
"""Base class for manipulating paths without I/O.
604+
605+
PurePath represents a filesystem path and offers operations which
604606
don't imply any actual filesystem I/O. Depending on your system,
605607
instantiating a PurePath will return either a PurePosixPath or a
606608
PureWindowsPath object. You can also instantiate either of these classes
@@ -955,11 +957,21 @@ def match(self, path_pattern):
955957

956958

957959
class PurePosixPath(PurePath):
960+
"""PurePath subclass for non-Windows systems.
961+
962+
On a POSIX system, instantiating a PurePath should return this object.
963+
However, you can also instantiate it directly on any system.
964+
"""
958965
_flavour = _posix_flavour
959966
__slots__ = ()
960967

961968

962969
class PureWindowsPath(PurePath):
970+
"""PurePath subclass for Windows systems.
971+
972+
On a Windows system, instantiating a PurePath should return this object.
973+
However, you can also instantiate it directly on any system.
974+
"""
963975
_flavour = _windows_flavour
964976
__slots__ = ()
965977

@@ -968,6 +980,14 @@ class PureWindowsPath(PurePath):
968980

969981

970982
class Path(PurePath):
983+
"""PurePath subclass that can make system calls.
984+
985+
Path represents a filesystem path but unlike PurePath, also offers
986+
methods to do system calls on path objects. Depending on your system,
987+
instantiating a Path will return either a PosixPath or a WindowsPath
988+
object. You can also instantiate a PosixPath or WindowsPath directly,
989+
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
990+
"""
971991
__slots__ = (
972992
'_accessor',
973993
'_closed',
@@ -1422,9 +1442,17 @@ def expanduser(self):
14221442

14231443

14241444
class PosixPath(Path, PurePosixPath):
1445+
"""Path subclass for non-Windows systems.
1446+
1447+
On a POSIX system, instantiating a Path should return this object.
1448+
"""
14251449
__slots__ = ()
14261450

14271451
class WindowsPath(Path, PureWindowsPath):
1452+
"""Path subclass for Windows systems.
1453+
1454+
On a Windows system, instantiating a Path should return this object.
1455+
"""
14281456
__slots__ = ()
14291457

14301458
def owner(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve docstrings for `pathlib.PurePath` subclasses.

0 commit comments

Comments
 (0)