@@ -54,8 +54,7 @@ def init_module(filesystem):
54
54
def _wrap_strfunc (strfunc ):
55
55
@functools .wraps (strfunc )
56
56
def _wrapped (pathobj , * args , ** kwargs ):
57
- p = pathobj .filesystem if hasattr (pathobj , "filesystem" ) else pathobj
58
- return strfunc (p , str (pathobj ), * args , ** kwargs )
57
+ return strfunc (pathobj .filesystem , str (pathobj ), * args , ** kwargs )
59
58
60
59
return staticmethod (_wrapped )
61
60
@@ -125,23 +124,19 @@ def lchmod(self, pathobj, mode):
125
124
FakeFilesystem .create_symlink (fs , file_path , link_target ,
126
125
create_missing_dirs = False ))
127
126
128
- if sys .version_info >= (3 , 8 ):
127
+ if ( 3 , 8 ) <= sys .version_info < (3 , 10 ):
129
128
link_to = _wrap_binary_strfunc (
130
129
lambda fs , file_path , link_target :
131
130
FakeFilesystem .link (fs , file_path , link_target ))
132
131
133
- if sys .version_info >= (3 , 9 ):
134
- readlink = _wrap_strfunc (FakeFilesystem .readlink )
135
- else :
136
- # why? and shouldnt this not be *os* -- but something patched (FakeOsModule probably)?
137
- readlink = staticmethod (os .readlink )
138
- pass
132
+ if sys .version_info >= (3 , 10 ):
133
+ link = _wrap_binary_strfunc (
134
+ lambda fs , file_path , link_target :
135
+ FakeFilesystem .link (fs , file_path , link_target ))
139
136
140
- utime = _wrap_strfunc (FakeFilesystem .utime )
137
+ readlink = _wrap_strfunc (FakeFilesystem .readlink )
141
138
142
- # same comment as above for these two
143
- realpath = staticmethod (os .path .realpath )
144
- getcwd = staticmethod (os .getcwd )
139
+ utime = _wrap_strfunc (FakeFilesystem .utime )
145
140
146
141
147
142
_fake_accessor = _FakeAccessor ()
@@ -471,15 +466,35 @@ def __new__(cls, *args, **kwargs):
471
466
if cls .filesystem .is_windows_fs
472
467
else FakePathlibModule .PosixPath )
473
468
self = cls ._from_parts (args )
469
+ return self
470
+
471
+ @classmethod
472
+ def _from_parts (cls , args , init = False ): # pylint: disable=unused-argument
473
+ # Overwritten to call _init to set the fake accessor,
474
+ # which is not done since Python 3.10
475
+ self = object .__new__ (cls )
474
476
self ._init ()
477
+ drv , root , parts = self ._parse_args (args )
478
+ self ._drv = drv
479
+ self ._root = root
480
+ self ._parts = parts
481
+ return self
482
+
483
+ @classmethod
484
+ def _from_parsed_parts (cls , drv , root , parts ):
485
+ # Overwritten to call _init to set the fake accessor,
486
+ # which is not done since Python 3.10
487
+ self = object .__new__ (cls )
488
+ self ._init ()
489
+ self ._drv = drv
490
+ self ._root = root
491
+ self ._parts = parts
475
492
return self
476
493
477
494
def _init (self , template = None ):
478
- """Initializer called from base class."""
479
- # template is an unused holdover
480
- _ = template
481
- self ._accessor = _fake_accessor
482
- self ._closed = False
495
+ """Initializer called from base class."""
496
+ self ._accessor = _fake_accessor
497
+ self ._closed = False
483
498
484
499
def _path (self ):
485
500
"""Returns the underlying path string as used by the fake filesystem.
@@ -729,20 +744,12 @@ class RealPath(pathlib.Path):
729
744
itself is not.
730
745
"""
731
746
732
- def _init (self , template = None ):
733
- """Initializer called from base class."""
734
- # template is an unused holdover
735
- _ = template
736
- self ._accessor = _fake_accessor
737
- self ._closed = False
738
-
739
747
def __new__ (cls , * args , ** kwargs ):
740
748
"""Creates the correct subclass based on OS."""
741
749
if cls is RealPathlibModule .Path :
742
750
cls = (RealPathlibModule .WindowsPath if os .name == 'nt'
743
751
else RealPathlibModule .PosixPath )
744
752
self = cls ._from_parts (args )
745
- self ._init ()
746
753
return self
747
754
748
755
0 commit comments