Skip to content

Commit b95de96

Browse files
authored
gh-105751: test_ctypes avoids "from ctypes import *" (#105768)
Using "import *" prevents linters like pyflakes to detect undefined names (usually missing imports). Replace c_voidp with c_void_p.
1 parent 381a1dc commit b95de96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+179
-83
lines changed

Lib/ctypes/_endian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from ctypes import *
2+
from ctypes import Array, Structure, Union
33

44
_array_type = type(Array)
55

Lib/test/test_ctypes/test_anon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
import test.support
3-
from ctypes import *
3+
from ctypes import c_int, Union, Structure, sizeof
44

55
class AnonTest(unittest.TestCase):
66

Lib/test/test_ctypes/test_array_in_pointer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from ctypes import *
2+
from ctypes import c_byte, Structure, POINTER, cast
33
from binascii import hexlify
44
import re
55

Lib/test/test_ctypes/test_arrays.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import sys
33
import unittest
44
import warnings
5-
from ctypes import *
5+
from ctypes import (Structure, Array, sizeof, addressof,
6+
create_string_buffer, create_unicode_buffer,
7+
c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
8+
c_long, c_ulonglong, c_float, c_double, c_longdouble)
69
from test.support import bigmemtest, _2G
710

811
from test.test_ctypes import need_symbol

Lib/test/test_ctypes/test_as_parameter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import unittest
1+
import _ctypes_test
22
import ctypes
3-
from ctypes import *
3+
import unittest
4+
from ctypes import (Structure, CDLL, CFUNCTYPE,
5+
POINTER, pointer, byref,
6+
c_short, c_int, c_long, c_longlong,
7+
c_byte, c_wchar, c_float, c_double,
8+
ArgumentError)
49
from test.test_ctypes import need_symbol
5-
import _ctypes_test
610

711
dll = CDLL(_ctypes_test.__file__)
812

Lib/test/test_ctypes/test_bitfields.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from ctypes import *
1+
from ctypes import (CDLL, Structure, sizeof, POINTER, byref, alignment,
2+
LittleEndianStructure, BigEndianStructure,
3+
c_byte, c_ubyte, c_char, c_char_p, c_void_p, c_wchar,
4+
c_uint32, c_uint64,
5+
c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong)
26
from test.test_ctypes import need_symbol
37
from test import support
48
import unittest

Lib/test/test_ctypes/test_buffers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from ctypes import *
1+
from ctypes import (create_string_buffer, create_unicode_buffer, sizeof,
2+
c_char, c_wchar)
23
from test.test_ctypes import need_symbol
34
import unittest
45

Lib/test/test_ctypes/test_bytes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test where byte objects are accepted"""
2-
import unittest
32
import sys
4-
from ctypes import *
3+
import unittest
4+
from ctypes import Structure, c_char, c_char_p, c_wchar, c_wchar_p
55

66
class BytesTest(unittest.TestCase):
77
def test_c_char(self):

Lib/test/test_ctypes/test_byteswap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import sys, unittest, struct, math, ctypes
22
from binascii import hexlify
33

4-
from ctypes import *
4+
from ctypes import (Structure, Union, LittleEndianUnion, BigEndianUnion,
5+
BigEndianStructure, LittleEndianStructure,
6+
POINTER, sizeof, cast,
7+
c_byte, c_ubyte, c_char, c_wchar, c_void_p,
8+
c_short, c_ushort, c_int, c_uint,
9+
c_long, c_ulong, c_longlong, c_ulonglong,
10+
c_uint32, c_float, c_double)
511

612
def bin(s):
713
return hexlify(memoryview(s)).decode().upper()

Lib/test/test_ctypes/test_callbacks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
from test import support
44

55
import ctypes
6-
from ctypes import *
6+
from ctypes import (CDLL, cdll, Structure, CFUNCTYPE,
7+
ArgumentError, POINTER, sizeof,
8+
c_byte, c_ubyte, c_char, c_char_p,
9+
c_short, c_ushort, c_int, c_uint,
10+
c_long, c_longlong, c_ulonglong, c_ulong,
11+
c_float, c_double, c_longdouble, py_object)
712
from test.test_ctypes import need_symbol
813
from _ctypes import CTYPES_MAX_ARGCOUNT
914
import _ctypes_test

0 commit comments

Comments
 (0)