The path.Path class in Libraries/Utility raises a TypeError: "unexpected keyword argument" when used from Python 3.10 or later.
It inherits pathlib.Path from Python's stdlib, and overrides the stat() method. It DOESN'T override pathlib.Path.exists(), which is implemented as (pseudo-code):
def exists(self, args):
try:
self.stat(args) # Calls the overridden stat() if self is a path.Path
except:
return False
return True
In Python 3.9's pathlib, exists() and stat() don't take any args, but in 3.10 they added a "follow_symlinks=True" keyword arg. So in Python 3.10 and later, exists() tries to call self.stat(follow_symlinks=True), which raises an exception because the overridden path.Path.stat doesn't expect follow_symlinks.
This makes path.Path.stat work with any Python version by adding *args, **kwargs that get passed through to pathlib.
The
path.Path
class in Libraries/Utility raises a TypeError: "unexpected keyword argument" when used from Python 3.10 or later.It inherits
pathlib.Path
from Python's stdlib, and overrides the stat() method. It DOESN'T overridepathlib.Path.exists()
, which is implemented as (pseudo-code):In Python 3.9's pathlib, exists() and stat() don't take any args, but in 3.10 they added a "follow_symlinks=True" keyword arg. So in Python 3.10 and later, exists() tries to call
self.stat(follow_symlinks=True)
, which raises an exception because the overridden path.Path.stat doesn't expectfollow_symlinks
.This makes
path.Path.stat
work with any Python version by adding*args, **kwargs
that get passed through to pathlib.