Skip to content

Commit f44693e

Browse files
authored
bpo-41477: Make ctypes optional in test_genericalias (pythonGH-21766)
1 parent 598a951 commit f44693e

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

Lib/test/test_genericalias.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from dataclasses import Field
1414
from functools import partial, partialmethod, cached_property
1515
from mailbox import Mailbox, _PartialFile
16-
from ctypes import Array, LibraryLoader
16+
try:
17+
import ctypes
18+
except ImportError:
19+
ctypes = None
1720
from difflib import SequenceMatcher
1821
from filecmp import dircmp
1922
from fileinput import FileInput
@@ -46,43 +49,44 @@ class BaseTest(unittest.TestCase):
4649
"""Test basics."""
4750

4851
def test_subscriptable(self):
49-
for t in (type, tuple, list, dict, set, frozenset, enumerate,
50-
defaultdict, deque,
51-
SequenceMatcher,
52-
dircmp,
53-
FileInput,
54-
OrderedDict, Counter, UserDict, UserList,
55-
Pattern, Match,
56-
partial, partialmethod, cached_property,
57-
AbstractContextManager, AbstractAsyncContextManager,
58-
Awaitable, Coroutine,
59-
AsyncIterable, AsyncIterator,
60-
AsyncGenerator, Generator,
61-
Iterable, Iterator,
62-
Reversible,
63-
Container, Collection,
64-
Callable,
65-
Mailbox, _PartialFile,
66-
ContextVar, Token,
67-
Field,
68-
Set, MutableSet,
69-
Mapping, MutableMapping, MappingView,
70-
KeysView, ItemsView, ValuesView,
71-
Sequence, MutableSequence,
72-
MappingProxyType, AsyncGeneratorType,
73-
DirEntry,
74-
chain,
75-
TemporaryDirectory, SpooledTemporaryFile,
76-
Queue, SimpleQueue,
77-
_AssertRaisesContext,
78-
Array, LibraryLoader,
79-
SplitResult, ParseResult,
80-
ValueProxy, ApplyResult,
81-
WeakSet, ReferenceType, ref,
82-
ShareableList, SimpleQueue,
83-
Future, _WorkItem,
84-
Morsel,
85-
):
52+
types = [type, tuple, list, dict, set, frozenset, enumerate,
53+
defaultdict, deque,
54+
SequenceMatcher,
55+
dircmp,
56+
FileInput,
57+
OrderedDict, Counter, UserDict, UserList,
58+
Pattern, Match,
59+
partial, partialmethod, cached_property,
60+
AbstractContextManager, AbstractAsyncContextManager,
61+
Awaitable, Coroutine,
62+
AsyncIterable, AsyncIterator,
63+
AsyncGenerator, Generator,
64+
Iterable, Iterator,
65+
Reversible,
66+
Container, Collection,
67+
Callable,
68+
Mailbox, _PartialFile,
69+
ContextVar, Token,
70+
Field,
71+
Set, MutableSet,
72+
Mapping, MutableMapping, MappingView,
73+
KeysView, ItemsView, ValuesView,
74+
Sequence, MutableSequence,
75+
MappingProxyType, AsyncGeneratorType,
76+
DirEntry,
77+
chain,
78+
TemporaryDirectory, SpooledTemporaryFile,
79+
Queue, SimpleQueue,
80+
_AssertRaisesContext,
81+
SplitResult, ParseResult,
82+
ValueProxy, ApplyResult,
83+
WeakSet, ReferenceType, ref,
84+
ShareableList, SimpleQueue,
85+
Future, _WorkItem,
86+
Morsel]
87+
if ctypes is not None:
88+
types.extend((ctypes.Array, ctypes.LibraryLoader))
89+
for t in types:
8690
if t is None:
8791
continue
8892
tname = t.__name__
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make ctypes optional in test_genericalias.

0 commit comments

Comments
 (0)