Skip to content

Run stubtest for Python 3.12 #10253

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 10 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/stubtest_stdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
matrix:
# tkinter doesn't import on macOS 12
os: ["ubuntu-latest", "windows-latest", "macos-11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
fail-fast: false

steps:
Expand Down
6 changes: 3 additions & 3 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ from typing import ( # noqa: Y022
overload,
type_check_only,
)
from typing_extensions import (
from typing_extensions import ( # type: ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These type ignores look like some pretty weird mypy bugginess surrounding LiteralString. I thought probably makes sense to just ignore for now and figure it out later, so we can test 3.12 effectively

Copy link
Member

Choose a reason for hiding this comment

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

Were you using mypy master when you ran tests locally for this PR? This looks like the regression I reported in python/mypy#15161 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Using mypy 1.3, I don't get any mypy or stubtest errors (on any Python version) if I remove these type: ignores, so I think it is the regression I noted in python/mypy#15161 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I'd missed that, it's definitely the same thing. Hmm, I'm not sure what the best way to proceed is.

Concatenate,
Literal,
LiteralString,
Expand Down Expand Up @@ -465,7 +465,7 @@ class str(Sequence[str]):
@overload
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
@overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore
def format_map(self, map: _FormatMapMapping) -> str: ...
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def isalnum(self) -> bool: ...
Expand Down Expand Up @@ -595,7 +595,7 @@ class str(Sequence[str]):
@overload
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
@overload
def __mod__(self, __value: Any) -> str: ...
def __mod__(self, __value: Any) -> str: ... # type: ignore
@overload
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
@overload
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/darwin-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ _?curses.color_pair
# ==========
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
49 changes: 49 additions & 0 deletions tests/stubtest_allowlists/darwin-py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
_?curses.color_pair
_curses.unget_wch
_curses.window.get_wch
_posixsubprocess.fork_exec
_socket.ETHERTYPE_ARP
_socket.ETHERTYPE_IP
_socket.ETHERTYPE_IPV6
_socket.ETHERTYPE_VLAN
_socket.IP_ADD_SOURCE_MEMBERSHIP
_socket.IP_BLOCK_SOURCE
_socket.IP_DROP_SOURCE_MEMBERSHIP
_socket.IP_PKTINFO
_socket.IP_UNBLOCK_SOURCE
curses.unget_wch
curses.window.get_wch
os.PRIO_DARWIN_BG
os.PRIO_DARWIN_NONUI
os.PRIO_DARWIN_PROCESS
os.PRIO_DARWIN_THREAD
posix.DirEntry.is_junction
posix.PRIO_DARWIN_BG
posix.PRIO_DARWIN_NONUI
posix.PRIO_DARWIN_PROCESS
posix.PRIO_DARWIN_THREAD
socket.ETHERTYPE_ARP
socket.ETHERTYPE_IP
socket.ETHERTYPE_IPV6
socket.ETHERTYPE_VLAN
socket.IP_ADD_SOURCE_MEMBERSHIP
socket.IP_BLOCK_SOURCE
socket.IP_DROP_SOURCE_MEMBERSHIP
socket.IP_PKTINFO
socket.IP_UNBLOCK_SOURCE
socket.TCP_CONNECTION_INFO
syslog.LOG_MASK
syslog.LOG_UPTO
syslog.setlogmask
tty.__all__
tty.cfmakecbreak
tty.cfmakeraw
xxlimited.Xxo.x_exports

(dbm.gnu)?
(locale.bind_textdomain_codeset)?
(locale.bindtextdomain)?
(locale.dcgettext)
(locale.dgettext)?
(locale.gettext)?
(locale.textdomain)?
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/darwin-py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pwd.getpwnam
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
5 changes: 0 additions & 5 deletions tests/stubtest_allowlists/darwin-py38.txt

This file was deleted.

5 changes: 0 additions & 5 deletions tests/stubtest_allowlists/darwin-py39.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ select.POLLMSG # system dependent
(termios.[A-Z0-9_]+)?

# Exists at runtime, but missing from stubs
distutils.msvccompiler.MSVCCompiler.get_msvc_paths
distutils.msvccompiler.MSVCCompiler.set_path_env_var
distutils.msvccompiler.MacroExpander
mimetypes.MimeTypes.read_windows_registry
selectors.DefaultSelector.fileno
socket.PF_SYSTEM
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/linux-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ signal.sigwaitinfo
# ==========
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
46 changes: 46 additions & 0 deletions tests/stubtest_allowlists/linux-py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
_?curses.color_pair
_posixsubprocess.fork_exec
(os|posix).CLONE_FILES
(os|posix).CLONE_FS
(os|posix).CLONE_NEWCGROUP
(os|posix).CLONE_NEWIPC
(os|posix).CLONE_NEWNET
(os|posix).CLONE_NEWNS
(os|posix).CLONE_NEWPID
(os|posix).CLONE_NEWUSER
(os|posix).CLONE_NEWUTS
(os|posix).CLONE_SIGHAND
(os|posix).CLONE_SYSVSEM
(os|posix).CLONE_THREAD
(os|posix).CLONE_VM
(os|posix).DirEntry.is_junction
(os|posix).EFD_CLOEXEC
(os|posix).EFD_NONBLOCK
(os|posix).EFD_SEMAPHORE
(os|posix).eventfd
(os|posix).eventfd_read
(os|posix).eventfd_write
(os|posix).sendfile
(os|posix).setns
(os|posix).setresgid
(os|posix).setresuid
(os|posix).splice
(os|posix).SPLICE_F_MORE
(os|posix).SPLICE_F_MOVE
(os|posix).SPLICE_F_NONBLOCK
(os|posix).unshare
fcntl.FICLONE
fcntl.FICLONERANGE
mmap.MAP_STACK
resource.prlimit
signal.sigtimedwait
signal.sigwaitinfo
ssl.OP_ENABLE_KTLS
ssl.Options.OP_ENABLE_KTLS
syslog.LOG_MASK
syslog.LOG_UPTO
syslog.setlogmask
tty.__all__
tty.cfmakecbreak
tty.cfmakeraw
xxlimited.Xxo.x_exports
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/linux-py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ pwd.getpwnam
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/linux-py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ select.epoll.register
# ==========
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/linux-py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ select.epoll.register
# ==========
# Allowlist entries that cannot or should not be fixed
# ==========

distutils.command.bdist_msi # Only available on Windows and Python 3.10 and below
3 changes: 0 additions & 3 deletions tests/stubtest_allowlists/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ socket.[A-Z0-9_]+
errno.[A-Z0-9]+

# Exists at runtime, but missing from stubs
distutils.msvccompiler.MSVCCompiler.get_msvc_paths
distutils.msvccompiler.MSVCCompiler.set_path_env_var
distutils.msvccompiler.MacroExpander
mimetypes.MimeTypes.read_windows_registry
selectors.DefaultSelector.fileno
spwd.struct_spwd.sp_nam
Expand Down
25 changes: 25 additions & 0 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ asyncio.Future.__init__ # Usually initialized from c object
asyncio.futures.Future.__init__ # Usually initialized from c object
builtins.float.__setformat__ # Internal method for CPython test suite
builtins.property.__set_name__ # Doesn't actually exist
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
configparser.ParsingError.filename
contextlib.AbstractAsyncContextManager.__class_getitem__
contextlib.AbstractContextManager.__class_getitem__
enum.Enum._generate_next_value_
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
gettext.install
gettext.translation
hmac.new # Stub is a white lie; see comments in the stub
importlib.abc.Finder.find_module
importlib.metadata._meta.SimplePath.__truediv__ # See comments in the stub
ipaddress.IPv4Interface.hostmask
ipaddress.IPv6Interface.hostmask
Expand Down Expand Up @@ -50,6 +54,13 @@ typing._TypedDict.update
typing._TypedDict.values
weakref.ProxyType.__reversed__ # Doesn't really exist
weakref.WeakValueDictionary.update
typing_extensions\.get_original_bases

# Exist at runtime for internal reasons, no need to put them in the stub
typing_extensions\.TypeAliasType\.__call__
typing_extensions\.TypeAliasType\.__init_subclass__
# We call them read-only properties, runtime implementation is slightly different
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__

# Runtime has *args, **kwargs, but will error if any are supplied
unittest.TestCase.__init_subclass__
Expand Down Expand Up @@ -183,3 +194,17 @@ typing.NewType.__call__
typing_extensions\.Final
typing\.NamedTuple
typing\.Annotated

# We lie about the existence of these methods
.*.__buffer__
.*.__release_buffer__

# Removed in 3.12
distutils\..*
Copy link
Member

Choose a reason for hiding this comment

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

I would have preferred to not do this. I feel like whenever we've used wildcard regex allowlist entries in the past, it's ended up causing us pain and confusion further down the line (#9900; #10205; there have been others as well).

If we have to do this, then we may as well revert the changes that were made to stubtest_stdlib.py in #9734. The venv module is really slow on Windows, so those changes basically doubled the time it takes for me to run the test locally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree in general, but I have basically no further interest in the accuracy of the distutil stubs, especially since most users aren't even going to get distutils when they import distutils. So that points to undo #9734. But I definitely wouldn't say "we have to do this"... let me know which one you want and I'll make the PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that all makes sense :-) let's go for undoing #9735, then.

Copy link
Member

Choose a reason for hiding this comment

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

Longer term, I guess we might want to look at getting type checkers to somehow recognise that if a user does import distutils with setuptools installed, they'll actually be getting setuptools._distutils... but the idea of adding that kind of special-casing to type checkers really doesn't fill me with joy.....

asyncore.dispatcher.addr
asyncore.dispatcher.handle_accepted
asynchat.async_chat.encoding
asynchat.async_chat.use_encoding
asynchat.find_prefix_at_end
pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*
25 changes: 25 additions & 0 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ _collections_abc.ValuesView.__reversed__
_csv.Reader
_csv.Writer
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
configparser.LegacyInterpolation.__init__
configparser.ParsingError.filename
enum.Enum._generate_next_value_
enum.Enum.__init__
# TODO: The stub for enum.auto is nothing like the implementation
enum.auto.__init__
Expand All @@ -22,6 +25,7 @@ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolv
ftplib.FTP.trust_server_pasv_ipv4_address
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
importlib.abc.Finder.find_module
ipaddress.IPv4Interface.hostmask
ipaddress.IPv6Interface.hostmask
ipaddress._BaseNetwork.broadcast_address
Expand All @@ -43,11 +47,18 @@ tkinter._VersionInfoType.__doc__
typing.NewType.__call__
typing.NewType.__mro_entries__
weakref.WeakValueDictionary.update
typing_extensions\.get_original_bases

# Runtime has *args, **kwargs, but will error if any are supplied
unittest.TestCase.__init_subclass__
unittest.case.TestCase.__init_subclass__

# Exist at runtime for internal reasons, no need to put them in the stub
typing_extensions\.TypeAliasType\.__call__
typing_extensions\.TypeAliasType\.__init_subclass__
# We call them read-only properties, runtime implementation is slightly different
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__

# ==========
# Related to positional-only arguments
# ==========
Expand Down Expand Up @@ -149,3 +160,17 @@ dataclasses.KW_ONLY
typing.ParamSpec(Args|Kwargs).__origin__
typing\.TypeVar\.__.*__
typing\.ParamSpec\.__.*__

# We lie about the existence of these methods
.*.__buffer__
.*.__release_buffer__

# Removed in 3.12
distutils\..*
asyncore.dispatcher.addr
asyncore.dispatcher.handle_accepted
asynchat.async_chat.encoding
asynchat.async_chat.use_encoding
asynchat.find_prefix_at_end
pkgutil.ImpImporter\..*
pkgutil.ImpLoader\..*
Loading