Skip to content

Improve __all__ definitions for threading and _dummy_threading modules #7135

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

Merged
merged 14 commits into from
Feb 5, 2022
Merged
20 changes: 19 additions & 1 deletion stdlib/@python2/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -6,7 +6,25 @@ _TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]

_PF = Callable[[FrameType, str, Any], None]

__all__: list[str]
__all__ = [
"activeCount",
"active_count",
"Condition",
"currentThread",
"current_thread",
"enumerate",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Timer",
"setprofile",
"settrace",
"local",
"stack_size",
]

def active_count() -> int: ...
def activeCount() -> int: ...
20 changes: 19 additions & 1 deletion stdlib/@python2/threading.pyi
Original file line number Diff line number Diff line change
@@ -6,7 +6,25 @@ _TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]

_PF = Callable[[FrameType, str, Any], None]

__all__: list[str]
__all__ = [
"activeCount",
"active_count",
"Condition",
"currentThread",
"current_thread",
"enumerate",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Timer",
"setprofile",
"settrace",
"local",
"stack_size",
]

def active_count() -> int: ...
def activeCount() -> int: ...
55 changes: 50 additions & 5 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -8,18 +8,63 @@ _TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]
_PF = Callable[[FrameType, str, Any], None]
_T = TypeVar("_T")

__all__: list[str]
if sys.version_info >= (3, 8):
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
"excepthook",
"ExceptHookArgs",
]
else:
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
]

def active_count() -> int: ...
def current_thread() -> Thread: ...
def currentThread() -> Thread: ...
def get_ident() -> int: ...
def enumerate() -> list[Thread]: ...
def main_thread() -> Thread: ...

if sys.version_info >= (3, 8):
from _thread import get_native_id as get_native_id

def settrace(func: _TF) -> None: ...
def setprofile(func: _PF | None) -> None: ...
def stack_size(size: int = ...) -> int: ...
81 changes: 80 additions & 1 deletion stdlib/threading.pyi
Original file line number Diff line number Diff line change
@@ -8,7 +8,86 @@ _TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]]
_PF = Callable[[FrameType, str, Any], None]
_T = TypeVar("_T")

__all__: list[str]
if sys.version_info >= (3, 10):
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
"excepthook",
"ExceptHookArgs",
"gettrace",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see these last two in the code on 3.9.

I do see get_native_id, though it looks like it's absent on some OSes: https://docs.python.org/3.10/library/threading.html#threading.get_native_id

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is a 3.10 block and gettrace and getprofile were only added in 3.10. Sorry for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on get_native_id. I was copy-pasting __all__ from the source code, and didn't spot that it was conditionally appended to __all__ lower down.

Copy link
Member Author

@AlexWaygood AlexWaygood Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added get_native_id to threading.__all__, and I have deleted get_native_id from _dummy_threading.pyi, as stubtest correctly points out that it doesn't exist in the dummy_threading at runtime on Python 3.8.

"getprofile",
"get_native_id",
]
elif sys.version_info >= (3, 8):
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
"excepthook",
"ExceptHookArgs",
"get_native_id",
]
else:
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
]

def active_count() -> int: ...
def activeCount() -> int: ... # deprecated alias for active_count()
22 changes: 4 additions & 18 deletions tests/stubtest_allowlists/py36.txt
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ distutils.cygwinccompiler.RE_VERSION
distutils.dist.command_re
distutils.fancy_getopt.longopt_re
distutils.fancy_getopt.neg_alias_re
dummy_threading.Condition.acquire
dummy_threading.Condition.release
dummy_threading.Event.isSet
dummy_threading.local.__new__
enum.Enum._generate_next_value_
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
hmac.HMAC.__init__
@@ -125,26 +129,8 @@ distutils.command.bdist_wininst
distutils.command.bdist_wininst.bdist_wininst
distutils.sysconfig.expand_makefile_vars
distutils.sysconfig.get_python_version
dummy_threading.Barrier
dummy_threading.BoundedSemaphore
dummy_threading.BrokenBarrierError
dummy_threading.Condition
dummy_threading.Event
dummy_threading.Lock
dummy_threading.RLock
dummy_threading.Semaphore
dummy_threading.TIMEOUT_MAX
dummy_threading.Thread
dummy_threading.ThreadError
dummy_threading.Timer
dummy_threading.active_count
dummy_threading.current_thread
dummy_threading.enumerate
dummy_threading.get_ident
dummy_threading.local
dummy_threading.main_thread
dummy_threading.setprofile
dummy_threading.settrace
dummy_threading.stack_size
html.parser.HTMLParser.unescape
platform.popen
22 changes: 4 additions & 18 deletions tests/stubtest_allowlists/py37.txt
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@ collections.UserString.maketrans
contextvars.Context.__init__ # Default C __init__ signature is wrong
contextvars.ContextVar.get
dataclasses.field
dummy_threading.Condition.acquire
dummy_threading.Condition.release
dummy_threading.Event.isSet
dummy_threading.local.__new__
enum.Enum._generate_next_value_
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
hmac.HMAC.__init__
@@ -102,26 +106,8 @@ distutils.cygwinccompiler.RE_VERSION
distutils.dist.command_re
distutils.fancy_getopt.longopt_re
distutils.fancy_getopt.neg_alias_re
dummy_threading.Barrier
dummy_threading.BoundedSemaphore
dummy_threading.BrokenBarrierError
dummy_threading.Condition
dummy_threading.Event
dummy_threading.Lock
dummy_threading.RLock
dummy_threading.Semaphore
dummy_threading.TIMEOUT_MAX
dummy_threading.Thread
dummy_threading.ThreadError
dummy_threading.Timer
dummy_threading.active_count
dummy_threading.current_thread
dummy_threading.enumerate
dummy_threading.get_ident
dummy_threading.local
dummy_threading.main_thread
dummy_threading.setprofile
dummy_threading.settrace
dummy_threading.stack_size
html.parser.HTMLParser.unescape
platform.popen
24 changes: 5 additions & 19 deletions tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
@@ -29,6 +29,11 @@ collections.KeysView.__reversed__
collections.ValuesView.__reversed__
contextvars.Context.__init__ # Default C __init__ signature is wrong
dataclasses.field
dummy_threading.Condition.acquire
dummy_threading.Condition.release
dummy_threading.Event.isSet
dummy_threading.Thread.native_id
dummy_threading.local.__new__
enum.Enum._generate_next_value_
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
@@ -115,28 +120,9 @@ distutils.cygwinccompiler.RE_VERSION
distutils.dist.command_re
distutils.fancy_getopt.longopt_re
distutils.fancy_getopt.neg_alias_re
dummy_threading.Barrier
dummy_threading.BoundedSemaphore
dummy_threading.BrokenBarrierError
dummy_threading.Condition
dummy_threading.Event
dummy_threading.ExceptHookArgs
dummy_threading.Lock
dummy_threading.RLock
dummy_threading.Semaphore
dummy_threading.TIMEOUT_MAX
dummy_threading.Thread
dummy_threading.ThreadError
dummy_threading.Timer
dummy_threading.active_count
dummy_threading.current_thread
dummy_threading.enumerate
dummy_threading.excepthook
dummy_threading.get_ident
dummy_threading.local
dummy_threading.main_thread
dummy_threading.setprofile
dummy_threading.settrace
dummy_threading.stack_size
html.parser.HTMLParser.unescape
multiprocessing.managers.SharedMemoryServer.create