From fef5d483a291d6a3029c01a03883c98b3a8f001a Mon Sep 17 00:00:00 2001 From: navigator Date: Fri, 20 Mar 2026 22:43:10 +0000 Subject: [PATCH 1/2] chore: migrate Python to 3.13 Automated migration by tkl-migrator - pyupgrade --py313-plus - autopep8 formatting - AI-assisted fixes for complex issues - Shebang updates --- pool_lib/__init__.py | 22 ++++++++++------------ tests/debversion.py | 6 ++++-- tests/emulcontainer.py | 1 - 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pool_lib/__init__.py b/pool_lib/__init__.py index ea06925..1abce58 100644 --- a/pool_lib/__init__.py +++ b/pool_lib/__init__.py @@ -149,7 +149,7 @@ def hardlink_or_copy(src: AnyPath, dst: AnyPath) -> None: @contextmanager -def in_dir(path: AnyPath) -> Generator[None, None, None]: +def in_dir(path: AnyPath) -> Generator[None]: """context manager to perform an operation within a specified directory""" cwd = os.getcwd() try: @@ -162,7 +162,7 @@ def in_dir(path: AnyPath) -> Generator[None, None, None]: class PackageCache: """Class representing the pool's package cache""" - def _list_binaries(self) -> Generator[str, None, None]: + def _list_binaries(self) -> Generator[str]: """List binaries in package cache -> list of package filenames""" for filename in os.listdir(self.path): filepath = join(self.path, filename) @@ -431,7 +431,7 @@ def dup_branch(branch: str) -> None: v = orig.rev_parse(tag) assert v is not None checkout.update_ref(f"refs/tags/{tag}", v) - except: # TODO don't use bare except! + except BaseException: # TODO don't use bare except! continue return checkout_path @@ -729,14 +729,12 @@ def unregister(self, stock_ref: str) -> None: blacklist: set[tuple[str, str]] = set() for path, versions in stock.sources: name = basename(path) - blacklist |= set([(name, version) for version in versions]) + blacklist |= {(name, version) for version in versions} - blacklist |= set( - [ - parse_package_filename(basename(path)) - for path in stock.binaries - ] - ) + blacklist |= { + parse_package_filename(basename(path)) + for path in stock.binaries + } removelist = set(self.pkgcache.list()) & blacklist for name, version in removelist: @@ -936,7 +934,7 @@ def _list( for stock in self.stocks: for path, versions in stock.sources: package = basename(path) - packages |= set([(package, version) for version in versions]) + packages |= {(package, version) for version in versions} if all_versions: return list(packages) @@ -1189,7 +1187,7 @@ def gc(self, recurse: bool = True, verbose: bool = True) -> None: for stock in self.stocks: for path, versions in stock.sources: name = basename(path) - whitelist |= set([(name, version) for version in versions]) + whitelist |= {(name, version) for version in versions} whitelist |= { parse_package_filename(basename(path)) diff --git a/tests/debversion.py b/tests/debversion.py index 1e29113..3e4d463 100644 --- a/tests/debversion.py +++ b/tests/debversion.py @@ -1,13 +1,15 @@ import re + def deb_compare_versions(a, b): """Compare a with b according to Debian versioning criteria""" def normalize(v): return re.sub(r'(\D|\b)0+', r'\1', v).rstrip("-") - + return cmp(normalize(a), normalize(b)) + def main(): dcv = deb_compare_versions assert dcv('1', '2') < 0 @@ -18,6 +20,6 @@ def main(): assert dcv('1.1', '1-1') > 0 assert dcv('1', '1-000') == 0 + if __name__ == "__main__": main() - diff --git a/tests/emulcontainer.py b/tests/emulcontainer.py index a3c59b4..64db730 100644 --- a/tests/emulcontainer.py +++ b/tests/emulcontainer.py @@ -10,4 +10,3 @@ def __setitem__(self, key, val): def __iter__(self): return iter(self.arr) - From 03ca88cf98151ccfe6526e86a41caf1ec24ecfc5 Mon Sep 17 00:00:00 2001 From: navigator Date: Fri, 20 Mar 2026 23:21:04 +0000 Subject: [PATCH 2/2] chore: migrate Python to 3.13 (8 files fixed) --- tests/classforked.py | 30 +++++++++++++++--------------- tests/constructor.py | 11 +++++------ tests/modifydefault.py | 5 ++--- tests/nestedclass.py | 11 ++++------- tests/printtrace.py | 10 ++-------- tests/setattr.py | 8 +++----- tests/test__new__.py | 13 ++++++------- tests/testpty.py | 16 ++++++---------- 8 files changed, 43 insertions(+), 61 deletions(-) diff --git a/tests/classforked.py b/tests/classforked.py index 7d2d911..a91b956 100644 --- a/tests/classforked.py +++ b/tests/classforked.py @@ -25,10 +25,10 @@ class Error(Exception): class Pipe: def __init__(self): r, w = os.pipe() - self.r = os.fdopen(r, "r", 0) - self.w = os.fdopen(w, "w", 0) + self.r = os.fdopen(r, "rb", 0) + self.w = os.fdopen(w, "wb", 0) -import new +import types class ProxyInstance: """This proxy class only proxies method invocations - no attributes""" def __init__(self, r, w): @@ -39,6 +39,7 @@ def __init__(self, r, w): def _proxy(attrname): def method(self, *args, **kws): pickle.dump((attrname, args, kws), self.w) + self.w.flush() error, val = pickle.load(self.r) if error: raise val @@ -46,10 +47,9 @@ def method(self, *args, **kws): return method def __getattr__(self, name): - print "GETATTR" + print("GETATTR") unbound_method = self._proxy(name) - method = new.instancemethod(unbound_method, - self, self.__class__) + method = types.MethodType(unbound_method, self) setattr(self, name, method) return method @@ -87,20 +87,20 @@ def Foo(): ret = attr(*args, **kws) pickle.dump((False, ret), w) - except Exception, e: + w.flush() + except Exception as e: pickle.dump((True, e), w) + w.flush() sys.exit(0) return ProxyInstance(r, w) -print "caller pid: %d" % os.getpid() +print("caller pid: %d" % os.getpid()) foo = Foo() -print "1 + 1 = %d" % foo.add(1, 1) -print "dict: " + `foo.makedict("liraz", age=26)` +print("1 + 1 = %d" % foo.add(1, 1)) +print("dict: " + repr(foo.makedict("liraz", age=26))) -print "foo pid: %d" % foo.getpid() -print "foo pid: %d" % foo.getpid() -print "foo uid: %d" % foo.getuid() - - +print("foo pid: %d" % foo.getpid()) +print("foo pid: %d" % foo.getpid()) +print("foo uid: %d" % foo.getuid()) \ No newline at end of file diff --git a/tests/constructor.py b/tests/constructor.py index a526021..75b1fe7 100644 --- a/tests/constructor.py +++ b/tests/constructor.py @@ -1,6 +1,6 @@ class B(object): def __init__(self, b): - print "B.__init__" + print("B.__init__") self.b = b def get(self): @@ -10,14 +10,13 @@ class A(B): def __new__(self, a): return a return B(a) - print "__new__(%s)" % `a` + print("__new__(%s)" % repr(a)) a = object.__new__(self, a) - print "foo" + print("foo") return a # return super(A, self).__new__(self, a) ## equivalent def __init__(self, a): - print "__init__(%s)" % `a` - self.a = a - + print("__init__(%s)" % repr(a)) + self.a = a \ No newline at end of file diff --git a/tests/modifydefault.py b/tests/modifydefault.py index b6a3f22..c4efa28 100644 --- a/tests/modifydefault.py +++ b/tests/modifydefault.py @@ -3,6 +3,5 @@ def func(var, arr=[]): return arr -print `func(1)` -print `func(2)` - +print(repr(func(1))) +print(repr(func(2))) \ No newline at end of file diff --git a/tests/nestedclass.py b/tests/nestedclass.py index 4e5cf54..b1bd65d 100644 --- a/tests/nestedclass.py +++ b/tests/nestedclass.py @@ -4,15 +4,12 @@ def __init__(self, var): class B: def foo(s): - print s - print self - print self.var + print(s) + print(self) + print(self.var) self.B = B a = A(666) b = a.B() -b.foo() - - - +b.foo() \ No newline at end of file diff --git a/tests/printtrace.py b/tests/printtrace.py index 50f169e..257565a 100644 --- a/tests/printtrace.py +++ b/tests/printtrace.py @@ -17,13 +17,7 @@ def main(): if __name__=="__main__": try: main() - except Exception, e: + except Exception as e: traceback.print_exc(file=sys.stderr) -# raise e.__class__, e, sys.exc_traceback - - - - - - +# raise e.__class__, e, sys.exc_traceback \ No newline at end of file diff --git a/tests/setattr.py b/tests/setattr.py index c3a466b..98d78ac 100644 --- a/tests/setattr.py +++ b/tests/setattr.py @@ -9,10 +9,8 @@ def __setattr__(self, attrname, val): object.__setattr__(self, attrname, val) return - print "__setattr__(%s, %s)" % (`attrname`, `val`) + print("__setattr__(%s, %s)" % (repr(attrname), repr(val))) a = A(111) -print a.a -print a.b - - +print(a.a) +print(a.b) \ No newline at end of file diff --git a/tests/test__new__.py b/tests/test__new__.py index 97725a4..e25742a 100644 --- a/tests/test__new__.py +++ b/tests/test__new__.py @@ -3,12 +3,11 @@ def __init__(self, b): self.b = b class A(object): - def __new__(self, a): - print "__new__(%s)" % `a` - return object.__new__(self, a) -# return super(A, self).__new__(self, a) ## equivalent + def __new__(cls, a): + print("__new__(%s)" % repr(a)) + return object.__new__(cls) +# return super(A, cls).__new__(cls) ## equivalent def __init__(self, a): - print "__init__(%s)" % `a` - self.a = a - + print("__init__(%s)" % repr(a)) + self.a = a \ No newline at end of file diff --git a/tests/testpty.py b/tests/testpty.py index 8a10ef4..96b35c5 100644 --- a/tests/testpty.py +++ b/tests/testpty.py @@ -8,12 +8,12 @@ if pid == 0: os.close(slave) while True: - print "child" - os.write(master, "ping") + print("child") + os.write(master, b"ping") buf = os.read(master, 4) if not buf: break - print "master read: " + buf + print("master read: " + buf.decode()) sys.exit(0) @@ -21,11 +21,7 @@ os.close(master) buf = os.read(slave, 4) if buf: - print "slave read: " + buf - os.write(slave, "pong") + print("slave read: " + buf.decode()) + os.write(slave, b"pong") os.close(slave) - time.sleep(5) - - - - + time.sleep(5) \ No newline at end of file