ITADN

Add kw args to Path.stat

#107Pull RequestJoeNotCharles 创建于 2024-06-07已合并
J
JoeNotCharlescommented
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.
合并状态:已合并 合并于 2024-07-05 关闭于 2024-07-05 1 条评论