Skip to content

Commit f39a208

Browse files
committed
ffi.py: Clean up imports
Flake8 reports several 'E402 module level import not at top of file' errors. Reorganize the imports to fix these errors and simplify imports. Specifically replace `from ctypes import` with simple `import ctypes' and define aliases below.
1 parent da7a747 commit f39a208

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

libarchive/ffi.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
from ctypes import (
2-
c_char_p, c_int, c_uint, c_long, c_longlong, c_size_t, c_int64,
3-
c_ubyte, c_void_p, c_wchar_p, CFUNCTYPE, POINTER,
4-
)
5-
6-
c_ubyte_p = POINTER(c_ubyte)
7-
8-
try:
9-
from ctypes import c_ssize_t
10-
except ImportError:
11-
from ctypes import c_longlong as c_ssize_t
12-
13-
import ctypes
141
from ctypes.util import find_library
2+
import ctypes
153
import logging
164
import mmap
175
import os
186
import sysconfig
197

208
from .exception import ArchiveError
219

10+
c_char_p = ctypes.c_char_p
11+
c_int = ctypes.c_int
12+
c_uint = ctypes.c_uint
13+
c_long = ctypes.c_long
14+
c_longlong = ctypes.c_longlong
15+
c_size_t = ctypes.c_size_t
16+
c_int64, = ctypes.c_int64,
17+
c_ubyte = ctypes.c_ubyte
18+
c_void_p = ctypes.c_void_p
19+
c_wchar_p = ctypes.c_wchar_p
20+
CFUNCTYPE = ctypes.CFUNCTYPE
21+
POINTER = ctypes.POINTER
22+
23+
c_ubyte_p = POINTER(c_ubyte)
24+
c_ssize_t = getattr(ctypes, 'c_ssize_t', c_longlong)
2225

2326
logger = logging.getLogger('libarchive')
2427

0 commit comments

Comments
 (0)