-
Notifications
You must be signed in to change notification settings - Fork 92
fix breaking pathlib change in 3.10 beta1 #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d12c9f6
311ec4c
39ac5fa
204e3cb
d6ae60b
02d5f69
affc4f3
b88851f
86bb5f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,8 @@ def init_module(filesystem): | |
|
||
def _wrap_strfunc(strfunc): | ||
@functools.wraps(strfunc) | ||
def _wrapped(pathobj, *args): | ||
return strfunc(pathobj.filesystem, str(pathobj), *args) | ||
def _wrapped(pathobj, *args, **kwargs): | ||
return strfunc(pathobj.filesystem, str(pathobj), *args, **kwargs) | ||
|
||
return staticmethod(_wrapped) | ||
|
||
|
@@ -94,19 +94,24 @@ class _FakeAccessor(accessor): | |
|
||
listdir = _wrap_strfunc(FakeFilesystem.listdir) | ||
|
||
chmod = _wrap_strfunc(FakeFilesystem.chmod) | ||
|
||
if use_scandir: | ||
scandir = _wrap_strfunc(fake_scandir.scandir) | ||
|
||
if hasattr(os, "lchmod"): | ||
lchmod = _wrap_strfunc(lambda fs, path, mode: FakeFilesystem.chmod( | ||
fs, path, mode, follow_symlinks=False)) | ||
chmod = _wrap_strfunc(FakeFilesystem.chmod) | ||
else: | ||
def lchmod(self, pathobj, mode): | ||
def lchmod(self, pathobj, *args, **kwargs): | ||
"""Raises not implemented for Windows systems.""" | ||
raise NotImplementedError("lchmod() not available on this system") | ||
|
||
def chmod(self, pathobj, *args, **kwargs): | ||
if "follow_symlinks" in kwargs and not kwargs["follow_symlinks"]: | ||
raise NotImplementedError( | ||
"lchmod() not available on this system") | ||
return pathobj.filesystem.chmod(str(pathobj), *args, **kwargs) | ||
|
||
mkdir = _wrap_strfunc(FakeFilesystem.makedir) | ||
|
||
unlink = _wrap_strfunc(FakeFilesystem.remove) | ||
|
@@ -124,13 +129,21 @@ def lchmod(self, pathobj, mode): | |
FakeFilesystem.create_symlink(fs, file_path, link_target, | ||
create_missing_dirs=False)) | ||
|
||
if sys.version_info >= (3, 8): | ||
if (3, 8) <= sys.version_info < (3, 10): | ||
link_to = _wrap_binary_strfunc( | ||
lambda fs, file_path, link_target: | ||
FakeFilesystem.link(fs, file_path, link_target)) | ||
|
||
if sys.version_info >= (3, 9): | ||
readlink = _wrap_strfunc(FakeFilesystem.readlink) | ||
if sys.version_info >= (3, 10): | ||
link = _wrap_binary_strfunc( | ||
lambda fs, file_path, link_target: | ||
FakeFilesystem.link(fs, file_path, link_target)) | ||
|
||
# this will use the fake filesystem because os is patched | ||
def getcwd(self): | ||
return os.getcwd() | ||
|
||
readlink = _wrap_strfunc(FakeFilesystem.readlink) | ||
|
||
utime = _wrap_strfunc(FakeFilesystem.utime) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this and the above section I am 99% sure I am doing something wrong/bad here -- but the gist of this is it looks like we needed to add some methods to the FakeAccessor object -- I am assuming(?) its not a great idea to just attach There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it accordingly. Regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed |
||
|
@@ -461,19 +474,42 @@ def __new__(cls, *args, **kwargs): | |
cls = (FakePathlibModule.WindowsPath | ||
if cls.filesystem.is_windows_fs | ||
else FakePathlibModule.PosixPath) | ||
self = cls._from_parts(args, init=True) | ||
self = cls._from_parts(args) | ||
return self | ||
|
||
def _path(self): | ||
"""Returns the underlying path string as used by the fake filesystem. | ||
""" | ||
return str(self) | ||
@classmethod | ||
def _from_parts(cls, args, init=False): # pylint: disable=unused-argument | ||
# Overwritten to call _init to set the fake accessor, | ||
# which is not done since Python 3.10 | ||
self = object.__new__(cls) | ||
self._init() | ||
drv, root, parts = self._parse_args(args) | ||
self._drv = drv | ||
self._root = root | ||
self._parts = parts | ||
return self | ||
|
||
@classmethod | ||
def _from_parsed_parts(cls, drv, root, parts): | ||
# Overwritten to call _init to set the fake accessor, | ||
# which is not done since Python 3.10 | ||
self = object.__new__(cls) | ||
self._init() | ||
self._drv = drv | ||
self._root = root | ||
self._parts = parts | ||
return self | ||
|
||
def _init(self, template=None): | ||
"""Initializer called from base class.""" | ||
self._accessor = _fake_accessor | ||
self._closed = False | ||
|
||
def _path(self): | ||
"""Returns the underlying path string as used by the fake filesystem. | ||
""" | ||
return str(self) | ||
|
||
@classmethod | ||
def cwd(cls): | ||
"""Return a new path pointing to the current working directory | ||
|
@@ -722,7 +758,7 @@ def __new__(cls, *args, **kwargs): | |
if cls is RealPathlibModule.Path: | ||
cls = (RealPathlibModule.WindowsPath if os.name == 'nt' | ||
else RealPathlibModule.PosixPath) | ||
self = cls._from_parts(args, init=True) | ||
self = cls._from_parts(args) | ||
return self | ||
mrbean-bremen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.