Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-43723: deprecate camelCase aliases from threading #25174

Merged
merged 7 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/faq/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ Here's a trivial example::
try:
arg = q.get(block=False)
except queue.Empty:
print('Worker', threading.currentThread(), end=' ')
print('Worker', threading.current_thread(), end=' ')
print('queue empty')
break
else:
print('Worker', threading.currentThread(), end=' ')
print('Worker', threading.current_thread(), end=' ')
print('running with argument', arg)
time.sleep(0.5)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/idle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ intended to be the same as executing the same code by the default method,
directly with Python in a text-mode system console or terminal window.
However, the different interface and operation occasionally affect
visible results. For instance, ``sys.modules`` starts with more entries,
and ``threading.activeCount()`` returns 2 instead of 1.
and ``threading.active_count()`` returns 2 instead of 1.

By default, IDLE runs user code in a separate OS process rather than in
the user interface process that runs the shell and editor. In the execution
Expand Down
19 changes: 17 additions & 2 deletions Doc/library/threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ level :mod:`_thread` module. See also the :mod:`queue` module.

.. note::

While they are not listed below, the ``camelCase`` names used for some
The ``camelCase`` names used for some
methods and functions in this module in the Python 2.x series are still
supported by this module.
supported by this module. They will be removed in the future.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved


.. impl-detail::
Expand All @@ -42,6 +42,8 @@ This module defines the following functions:
Return the number of :class:`Thread` objects currently alive. The returned
count is equal to the length of the list returned by :func:`.enumerate`.

.. deprecated-removed:: 3.10 3.12
The function `activeCount` is an alias for this function.
vstinner marked this conversation as resolved.
Show resolved Hide resolved

.. function:: current_thread()

Expand All @@ -50,6 +52,9 @@ This module defines the following functions:
:mod:`threading` module, a dummy thread object with limited functionality is
returned.

.. deprecated-removed:: 3.10 3.12
The function `currentThread` is an alias for this function.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved


.. function:: excepthook(args, /)

Expand Down Expand Up @@ -384,6 +389,8 @@ since it is impossible to detect the termination of alien threads.
Old getter/setter API for :attr:`~Thread.name`; use it directly as a
property instead.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

.. deprecated-removed:: 3.10 3.12

.. attribute:: ident

The 'thread identifier' of this thread or ``None`` if the thread has not
Expand Down Expand Up @@ -436,6 +443,8 @@ since it is impossible to detect the termination of alien threads.
Old getter/setter API for :attr:`~Thread.daemon`; use it directly as a
property instead.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

.. deprecated-removed:: 3.10 3.12


.. _lock-objects:

Expand Down Expand Up @@ -771,6 +780,9 @@ item to the buffer only needs to wake up one consumer thread.
calling thread has not acquired the lock when this method is called, a
:exc:`RuntimeError` is raised.

.. deprecated-removed:: 3.10 3.12
The method `notifyAll` is an alias for this method.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved


.. _semaphore-objects:

Expand Down Expand Up @@ -908,6 +920,9 @@ method. The :meth:`~Event.wait` method blocks until the flag is true.

Return ``True`` if and only if the internal flag is true.

.. deprecated-removed:: 3.10 3.12
The method `isSet` is an alias for this method.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

.. method:: set()

Set the internal flag to true. All threads waiting for it to become true
Expand Down
31 changes: 23 additions & 8 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def test_various_ops(self):

def test_ident_of_no_threading_threads(self):
# The ident still must work for the main thread and dummy threads.
self.assertIsNotNone(threading.currentThread().ident)
self.assertIsNotNone(threading.current_thread().ident)
def f():
ident.append(threading.currentThread().ident)
ident.append(threading.current_thread().ident)
done.set()
done = threading.Event()
ident = []
Expand Down Expand Up @@ -447,13 +447,28 @@ def test_old_threading_api(self):
# Just a quick sanity check to make sure the old method names are
# still present
t = threading.Thread()
t.isDaemon()
t.setDaemon(True)
t.getName()
t.setName("name")
with self.assertWarnsRegex(DeprecationWarning, r'use \.daemon'):
t.isDaemon()
with self.assertWarnsRegex(DeprecationWarning, r'use \.daemon'):
t.setDaemon(True)
with self.assertWarnsRegex(DeprecationWarning, r'use \.name'):
t.getName()
with self.assertWarnsRegex(DeprecationWarning, r'use \.name'):
t.setName("name")

e = threading.Event()
e.isSet()
threading.activeCount()
with self.assertWarnsRegex(DeprecationWarning, 'use is_set()'):
e.isSet()

cond = threading.Condition()
cond.acquire()
with self.assertWarnsRegex(DeprecationWarning, 'use notify_all()'):
cond.notifyAll()

with self.assertWarnsRegex(DeprecationWarning, 'use active_count()'):
threading.activeCount()
with self.assertWarnsRegex(DeprecationWarning, 'use current_thread()'):
threading.currentThread()

def test_repr_daemon(self):
t = threading.Thread()
Expand Down
76 changes: 72 additions & 4 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,16 @@ def notify_all(self):
"""
self.notify(len(self._waiters))

notifyAll = notify_all
def notifyAll(self):
"""Wake up all threads waiting on this condition.

This method is deprecated, use notify_all() instead.

"""
import warnings
warnings.warn('notifyAll() is deprecated, use notify_all() instead',
DeprecationWarning, stacklevel=2)
self.notify_all()


class Semaphore:
Expand Down Expand Up @@ -538,7 +547,16 @@ def is_set(self):
"""Return true if and only if the internal flag is true."""
return self._flag

isSet = is_set
def isSet(self):
"""Return true if and only if the internal flag is true.

This method is deprecated, use notify_all() instead.

"""
import warnings
warnings.warn('isSet() is deprecated, use is_set() instead',
DeprecationWarning, stacklevel=2)
return self.is_set()

def set(self):
"""Set the internal flag to true.
Expand Down Expand Up @@ -1146,15 +1164,47 @@ def daemon(self, daemonic):
self._daemonic = daemonic

def isDaemon(self):
"""Return whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

"""
import warnings
warnings.warn('isDaemon() is deprecated, use .daemon instead',
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
DeprecationWarning, stacklevel=2)
return self.daemon

def setDaemon(self, daemonic):
"""Set whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

"""
import warnings
warnings.warn('setDaemon() is deprecated, use .daemon instead',
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
DeprecationWarning, stacklevel=2)
self.daemon = daemonic

def getName(self):
"""Return a string used for identification purposes only.

This method is deprecated, use the .name property instead.

"""
import warnings
warnings.warn('getName() is deprecated, use .name instead',
DeprecationWarning, stacklevel=2)
return self.name

def setName(self, name):
"""Set the name string for this thread.

This method is deprecated, use the .name property instead.

"""
import warnings
warnings.warn('setName() is deprecated, use .name instead',
DeprecationWarning, stacklevel=2)
self.name = name


Expand Down Expand Up @@ -1349,7 +1399,16 @@ def current_thread():
except KeyError:
return _DummyThread()

currentThread = current_thread
def currentThread():
"""Return the current Thread object, corresponding to the caller's thread of control.

This function is deprecated, use current_thread() instead.

"""
import warnings
warnings.warn('currentThread() is deprecated, use current_thread() instead',
DeprecationWarning, stacklevel=2)
return current_thread()

def active_count():
"""Return the number of Thread objects currently alive.
Expand All @@ -1361,7 +1420,16 @@ def active_count():
with _active_limbo_lock:
return len(_active) + len(_limbo)

activeCount = active_count
def activeCount():
"""Return the number of Thread objects currently alive.

This function is deprecated, use active_count() instead.

"""
import warnings
warnings.warn('activeCount() is deprecated, use active_count() instead',
DeprecationWarning, stacklevel=2)
return active_count()

def _enumerate():
# Same as enumerate(), but without the lock. Internal use only.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The following `threading` methods are now deprecated:
`threading.currentThread`, `threading.activeCount`,
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
`threading.Condition.notifyAll`, `threading.Event.isSet`,
`threading.Thread.setName`, `threading.thread.getName`,
`threading.Thread.isDaemon`, and `threading.Thread.setDaemon`. Patch by
Jelle Zijlstra.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved