@@ -613,41 +613,44 @@ class PureWindowsPath(PurePath):
613613 __slots__ = ()
614614
615615
616- class _Info :
616+ class Info :
617+ """Implementation of pathlib.types.PathInfo that provides cached
618+ information about a local filesystem path. Don't try to construct it
619+ yourself.
620+ """
617621 __slots__ = ('_path' ,)
618622
619623 def __init__ (self , path ):
624+ if type (self ) is Info :
625+ raise TypeError ('Info cannot be directly instantiated; '
626+ 'use Path.info instead.' )
620627 self ._path = path
621628
622- def __repr__ (self ):
623- path_type = "WindowsPath" if os .name == "nt" else "PosixPath"
624- return f"<{ path_type } .info>"
625-
626- def _stat (self , * , follow_symlinks = True ):
629+ def stat (self , * , follow_symlinks = True ):
627630 """Return the status as an os.stat_result."""
628631 raise NotImplementedError
629632
630633 def _posix_permissions (self , * , follow_symlinks = True ):
631634 """Return the POSIX file permissions."""
632- return S_IMODE (self ._stat (follow_symlinks = follow_symlinks ).st_mode )
635+ return S_IMODE (self .stat (follow_symlinks = follow_symlinks ).st_mode )
633636
634637 def _file_id (self , * , follow_symlinks = True ):
635638 """Returns the identifier of the file."""
636- st = self ._stat (follow_symlinks = follow_symlinks )
639+ st = self .stat (follow_symlinks = follow_symlinks )
637640 return st .st_dev , st .st_ino
638641
639642 def _access_time_ns (self , * , follow_symlinks = True ):
640643 """Return the access time in nanoseconds."""
641- return self ._stat (follow_symlinks = follow_symlinks ).st_atime_ns
644+ return self .stat (follow_symlinks = follow_symlinks ).st_atime_ns
642645
643646 def _mod_time_ns (self , * , follow_symlinks = True ):
644647 """Return the modify time in nanoseconds."""
645- return self ._stat (follow_symlinks = follow_symlinks ).st_mtime_ns
648+ return self .stat (follow_symlinks = follow_symlinks ).st_mtime_ns
646649
647650 if hasattr (os .stat_result , 'st_flags' ):
648651 def _bsd_flags (self , * , follow_symlinks = True ):
649652 """Return the flags."""
650- return self ._stat (follow_symlinks = follow_symlinks ).st_flags
653+ return self .stat (follow_symlinks = follow_symlinks ).st_flags
651654
652655 if hasattr (os , 'listxattr' ):
653656 def _xattrs (self , * , follow_symlinks = True ):
@@ -666,7 +669,7 @@ def _xattrs(self, *, follow_symlinks=True):
666669_STAT_RESULT_ERROR = [] # falsy sentinel indicating stat() failed.
667670
668671
669- class _StatResultInfo (_Info ):
672+ class _StatResultInfo (Info ):
670673 """Implementation of pathlib.types.PathInfo that provides status
671674 information by querying a wrapped os.stat_result object. Don't try to
672675 construct it yourself."""
@@ -677,7 +680,7 @@ def __init__(self, path):
677680 self ._stat_result = None
678681 self ._lstat_result = None
679682
680- def _stat (self , * , follow_symlinks = True ):
683+ def stat (self , * , follow_symlinks = True ):
681684 """Return the status as an os.stat_result."""
682685 if follow_symlinks :
683686 if not self ._stat_result :
@@ -705,7 +708,7 @@ def exists(self, *, follow_symlinks=True):
705708 if self ._lstat_result is _STAT_RESULT_ERROR :
706709 return False
707710 try :
708- self ._stat (follow_symlinks = follow_symlinks )
711+ self .stat (follow_symlinks = follow_symlinks )
709712 except (OSError , ValueError ):
710713 return False
711714 return True
@@ -719,7 +722,7 @@ def is_dir(self, *, follow_symlinks=True):
719722 if self ._lstat_result is _STAT_RESULT_ERROR :
720723 return False
721724 try :
722- st = self ._stat (follow_symlinks = follow_symlinks )
725+ st = self .stat (follow_symlinks = follow_symlinks )
723726 except (OSError , ValueError ):
724727 return False
725728 return S_ISDIR (st .st_mode )
@@ -733,7 +736,7 @@ def is_file(self, *, follow_symlinks=True):
733736 if self ._lstat_result is _STAT_RESULT_ERROR :
734737 return False
735738 try :
736- st = self ._stat (follow_symlinks = follow_symlinks )
739+ st = self .stat (follow_symlinks = follow_symlinks )
737740 except (OSError , ValueError ):
738741 return False
739742 return S_ISREG (st .st_mode )
@@ -743,13 +746,13 @@ def is_symlink(self):
743746 if self ._lstat_result is _STAT_RESULT_ERROR :
744747 return False
745748 try :
746- st = self ._stat (follow_symlinks = False )
749+ st = self .stat (follow_symlinks = False )
747750 except (OSError , ValueError ):
748751 return False
749752 return S_ISLNK (st .st_mode )
750753
751754
752- class _DirEntryInfo (_Info ):
755+ class _DirEntryInfo (Info ):
753756 """Implementation of pathlib.types.PathInfo that provides status
754757 information by querying a wrapped os.DirEntry object. Don't try to
755758 construct it yourself."""
@@ -759,7 +762,7 @@ def __init__(self, entry):
759762 super ().__init__ (entry .path )
760763 self ._entry = entry
761764
762- def _stat (self , * , follow_symlinks = True ):
765+ def stat (self , * , follow_symlinks = True ):
763766 """Return the status as an os.stat_result."""
764767 return self ._entry .stat (follow_symlinks = follow_symlinks )
765768
@@ -768,7 +771,7 @@ def exists(self, *, follow_symlinks=True):
768771 if not follow_symlinks :
769772 return True
770773 try :
771- self ._stat (follow_symlinks = follow_symlinks )
774+ self .stat (follow_symlinks = follow_symlinks )
772775 except OSError :
773776 return False
774777 return True
0 commit comments