Add further types to `_INVALID_BUILTIN_CLASSES` (#13263)

This commit is contained in:
Adam Turner authored and GitHub committed 2025-01-23 03:53:25 +00:00
1 parent 47bff3faea
commit ca2ab35d94
4 files changed
+116 -3

No files matched your search

+76
View File
@@ -2,12 +2,27 @@
from __future__ import annotations
import ctypes
import dataclasses
import sys
import typing as t
import zipfile
from collections import abc
from contextvars import Context, ContextVar, Token
from enum import Enum
from io import (
BufferedRandom,
BufferedReader,
BufferedRWPair,
BufferedWriter,
BytesIO,
FileIO,
StringIO,
TextIOWrapper,
)
from json import JSONDecoder, JSONEncoder
from lzma import LZMACompressor, LZMADecompressor
from multiprocessing import Process
from numbers import Integral
from pathlib import (
Path,
@@ -17,6 +32,7 @@ from pathlib import (
PureWindowsPath,
WindowsPath,
)
from pickle import Pickler, Unpickler
from struct import Struct
from types import (
AsyncGeneratorType,
@@ -57,6 +73,7 @@ from typing import (
TypeVar,
Union,
)
from weakref import WeakSet
from sphinx.ext.autodoc import mock
from sphinx.util.typing import _INVALID_BUILTIN_CLASSES, restify, stringify_annotation
@@ -129,6 +146,27 @@ def test_is_invalid_builtin_class():
Context,
ContextVar,
Token,
# ctypes
ctypes.Array,
ctypes.Structure,
ctypes.Union,
# io
FileIO,
BytesIO,
StringIO,
BufferedReader,
BufferedWriter,
BufferedRWPair,
BufferedRandom,
TextIOWrapper,
# json
JSONDecoder,
JSONEncoder,
# lzma
LZMACompressor,
LZMADecompressor,
# multiprocessing
Process,
# pathlib
Path,
PosixPath,
@@ -136,6 +174,9 @@ def test_is_invalid_builtin_class():
PurePosixPath,
PureWindowsPath,
WindowsPath,
# pickle
Pickler,
Unpickler,
# struct
Struct,
# types
@@ -162,11 +203,37 @@ def test_is_invalid_builtin_class():
NotImplementedType,
TracebackType,
WrapperDescriptorType,
# weakref
WeakSet,
# zipfile
zipfile.Path,
zipfile.CompleteDirs,
}
# contextvars
assert Context.__module__ == '_contextvars'
assert ContextVar.__module__ == '_contextvars'
assert Token.__module__ == '_contextvars'
# ctypes
assert ctypes.Array.__module__ == '_ctypes'
assert ctypes.Structure.__module__ == '_ctypes'
assert ctypes.Union.__module__ == '_ctypes'
# io
assert FileIO.__module__ == '_io'
assert BytesIO.__module__ == '_io'
assert StringIO.__module__ == '_io'
assert BufferedReader.__module__ == '_io'
assert BufferedWriter.__module__ == '_io'
assert BufferedRWPair.__module__ == '_io'
assert BufferedRandom.__module__ == '_io'
assert TextIOWrapper.__module__ == '_io'
# json
assert JSONDecoder.__module__ == 'json.decoder'
assert JSONEncoder.__module__ == 'json.encoder'
# lzma
assert LZMACompressor.__module__ == '_lzma'
assert LZMADecompressor.__module__ == '_lzma'
# multiprocessing
assert Process.__module__ == 'multiprocessing.context'
if sys.version_info[:2] >= (3, 13):
# pathlib
assert Path.__module__ == 'pathlib._local'
@@ -175,6 +242,9 @@ def test_is_invalid_builtin_class():
assert PurePosixPath.__module__ == 'pathlib._local'
assert PureWindowsPath.__module__ == 'pathlib._local'
assert WindowsPath.__module__ == 'pathlib._local'
# pickle
assert Pickler.__module__ == '_pickle'
assert Unpickler.__module__ == '_pickle'
# struct
assert Struct.__module__ == '_struct'
# types
@@ -201,6 +271,12 @@ def test_is_invalid_builtin_class():
assert NotImplementedType.__module__ == 'builtins'
assert TracebackType.__module__ == 'builtins'
assert WrapperDescriptorType.__module__ == 'builtins'
# weakref
assert WeakSet.__module__ == '_weakrefset'
if sys.version_info[:2] >= (3, 12):
# zipfile
assert zipfile.Path.__module__ == 'zipfile._path'
assert zipfile.CompleteDirs.__module__ == 'zipfile._path'
def test_restify_type_hints_containers():