diff --git a/Doc/deprecations/pending-removal-in-3.21.rst b/Doc/deprecations/pending-removal-in-3.21.rst index c2546b7fc451aed..4577ad083323ede 100644 --- a/Doc/deprecations/pending-removal-in-3.21.rst +++ b/Doc/deprecations/pending-removal-in-3.21.rst @@ -28,3 +28,13 @@ Pending removal in Python 3.21 * ``tempfile._TemporaryFileWrapper`` will be removed in Python 3.21. Use the public :class:`tempfile.TemporaryFileWrapper` instead. + +* :mod:`threading`: + + * ``threading.Condition.notifyAll``, ``threading.Event.isSet``, and + ``threading.activeCount`` will be removed in Python 3.21. Use the snake case + names (e.g., ``notify_all``) instead. + * ``threading.Thread.isDaemon``, ``threading.Thread.setDaemon`` will be removed + in Python 3.21. Use the property ``threading.Thread.daemon`` instead. + * ``threading.Thread.getName`` and ``threading.Thread.setName`` will be removed + in Python 3.21. Use the property ``threading.Thread.name`` instead. diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index c06e6930ac78bff..fc0e8fa7a606119 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -720,6 +720,16 @@ New deprecations Use the new public :class:`tempfile.TemporaryFileWrapper` instead, which is the return type of :func:`tempfile.NamedTemporaryFile`. +* :mod:`threading`: + + * ``threading.Condition.notifyAll``, ``threading.Event.isSet``, and + ``threading.activeCount`` will be removed in Python 3.21. Use the snake case + names (e.g., ``notify_all``) instead. + * ``threading.Thread.isDaemon``, ``threading.Thread.setDaemon`` will be removed + in Python 3.21. Use the property ``threading.Thread.daemon`` instead. + * ``threading.Thread.getName`` and ``threading.Thread.setName`` will be removed + in Python 3.21. Use the property ``threading.Thread.name`` instead. + * :mod:`tkinter`: * :func:`tkinter.filedialog.askopenfiles` is deprecated and slated for diff --git a/Lib/threading.py b/Lib/threading.py index abac31e25886fae..6fe1bfed10ad11b 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -4,6 +4,7 @@ import sys as _sys import _thread import _contextvars +lazy import warnings from time import monotonic as _time from _weakrefset import WeakSet @@ -444,9 +445,7 @@ def notifyAll(self): This method is deprecated, use notify_all() instead. """ - import warnings - warnings.warn('notifyAll() is deprecated, use notify_all() instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated("notifyAll", 'notifyAll() is deprecated, use notify_all() instead', remove=(3, 21)) self.notify_all() @@ -616,9 +615,7 @@ def isSet(self): This method is deprecated, use is_set() instead. """ - import warnings - warnings.warn('isSet() is deprecated, use is_set() instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated("isSet", 'isSet() is deprecated, use is_set() instead', remove=(3, 21)) return self.is_set() def set(self): @@ -1352,9 +1349,7 @@ def isDaemon(self): This method is deprecated, use the daemon attribute instead. """ - import warnings - warnings.warn('isDaemon() is deprecated, get the daemon attribute instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('isDaemon', 'isDaemon() is deprecated, get the daemon attribute instead',remove=(3,21)) return self.daemon def setDaemon(self, daemonic): @@ -1363,9 +1358,7 @@ def setDaemon(self, daemonic): This method is deprecated, use the .daemon property instead. """ - import warnings - warnings.warn('setDaemon() is deprecated, set the daemon attribute instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('setDaemon', 'setDaemon() is deprecated, set the daemon attribute instead', remove=(3,21)) self.daemon = daemonic def getName(self): @@ -1374,9 +1367,7 @@ def getName(self): This method is deprecated, use the name attribute instead. """ - import warnings - warnings.warn('getName() is deprecated, get the name attribute instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('getName', 'getName() is deprecated, get the name attribute instead', remove=(3,21)) return self.name def setName(self, name): @@ -1385,9 +1376,7 @@ def setName(self, name): This method is deprecated, use the name attribute instead. """ - import warnings - warnings.warn('setName() is deprecated, set the name attribute instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('setName', 'setName() is deprecated, set the name attribute instead', remove=(3,21)) self.name = name @@ -1621,9 +1610,7 @@ def currentThread(): This function is deprecated, use current_thread() instead. """ - import warnings - warnings.warn('currentThread() is deprecated, use current_thread() instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('currentThread', 'currentThread() is deprecated, use current_thread() instead', remove=(3,21)) return current_thread() def active_count(): @@ -1644,9 +1631,7 @@ def activeCount(): This function is deprecated, use active_count() instead. """ - import warnings - warnings.warn('activeCount() is deprecated, use active_count() instead', - DeprecationWarning, stacklevel=2) + warnings._deprecated('activeCount', 'activeCount() is deprecated, use active_count() instead', remove=(3,21)) return active_count() def _enumerate(): diff --git a/Misc/NEWS.d/next/Library/2026-07-19-17-39-08.gh-issue-154205.B9rNEh.rst b/Misc/NEWS.d/next/Library/2026-07-19-17-39-08.gh-issue-154205.B9rNEh.rst new file mode 100644 index 000000000000000..7350a53a02414f1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-19-17-39-08.gh-issue-154205.B9rNEh.rst @@ -0,0 +1,5 @@ +The methods ``threading.Condition.notifyAll``, ``threading.Event.isSet``, +``threading.Thread.isDaemon``, ``threading.Thread.setDaemon``, +``threading.Thread.getName``, ``threading.Thread.setName``, and the function +``threading.activeCount``, which have been deprecated since Python 3.10, are +now scheduled for removal in Python 3.21.