NickHugi / PyKotor

A Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Add kw args to Path.stat #107

Closed JoeNotCharles closed 2 months ago

JoeNotCharles commented 3 months ago

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.

th3w1zard1 commented 2 months ago

What are we even doing with _last_stat_result...

LGTM, nice work 👍