From feab723c59a9996407ba312ba8ae263d2ff7ed2b Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Mar 11 2022 18:37:08 +0000 Subject: pylint: Fix deprecated-method for threading As of Python3 `currentThread`, `thread.getName` are aliases for `threading.current_thread()` and `threading.Thread.name` respectively. In Python3.10: > bpo-43723: The following threading methods are now deprecated and should be replaced: currentThread => threading.current_thread() activeCount => threading.active_count() Condition.notifyAll => threading.Condition.notify_all() Event.isSet => threading.Event.is_set() Thread.setName => threading.Thread.name thread.getName => threading.Thread.name Thread.isDaemon => threading.Thread.daemon Thread.setDaemon => threading.Thread.daemon Fixes: https://pagure.io/freeipa/issue/9117 Signed-off-by: Stanislav Levin Reviewed-By: Rob Crittenden --- diff --git a/ipalib/backend.py b/ipalib/backend.py index 89c9a5a..553dbff 100644 --- a/ipalib/backend.py +++ b/ipalib/backend.py @@ -63,7 +63,7 @@ class Connectible(Backend): "{0} is already connected ({1} in {2})".format( self.name, self.id, - threading.currentThread().getName() + threading.current_thread().name, ) ) conn = self.create_connection(*args, **kw) @@ -80,7 +80,7 @@ class Connectible(Backend): "{0} is not connected ({1} in {2})".format( self.name, self.id, - threading.currentThread().getName() + threading.current_thread().name, ) ) self.destroy_connection() @@ -105,7 +105,7 @@ class Connectible(Backend): "{0} is not connected ({1} in {2})".format( self.name, self.id, - threading.currentThread().getName() + threading.current_thread().name, ) ) return getattr(context, self.id).conn diff --git a/ipatests/test_ipalib/test_backend.py b/ipatests/test_ipalib/test_backend.py index b587029..e43830a 100644 --- a/ipatests/test_ipalib/test_backend.py +++ b/ipatests/test_ipalib/test_backend.py @@ -94,7 +94,8 @@ class test_Connectible(ClassChecker): m = "{0} is already connected ({1} in {2})" e = raises(Exception, o.connect, *args, **kw) assert str(e) == m.format( - 'example', o.id, threading.currentThread().getName()) + "example", o.id, threading.current_thread().name + ) # Double check that it works after deleting context.example: del context.example @@ -124,7 +125,8 @@ class test_Connectible(ClassChecker): m = "{0} is not connected ({1} in {2})" e = raises(Exception, o.disconnect) assert str(e) == m.format( - 'example', o.id, threading.currentThread().getName()) + "example", o.id, threading.current_thread().name + ) context.example = 'The connection.' assert o.disconnect() is None @@ -169,7 +171,7 @@ class test_Connectible(ClassChecker): o = klass(api, shared_instance=True) e = raises(AttributeError, getattr, o, 'conn') assert str(e) == msg.format( - klass.__name__, o.id, threading.currentThread().getName() + klass.__name__, o.id, threading.current_thread().name ) conn = Connection('The connection.', Disconnect()) setattr(context, klass.__name__, conn)