From 616268ab69aad4e9229c5ed9444793edc3da8996 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 27 Jul 2024 07:19:12 +0200 Subject: [PATCH] ruff check --select=E --fix --unsafe-fixes --- demo/cffi-cocoa.py | 12 ++++----- demo/pwuid.py | 3 ++- demo/winclipboard.py | 3 ++- demo/xclient.py | 3 ++- doc/source/conf.py | 3 ++- setup.py | 4 ++- setup_base.py | 3 ++- src/c/test_c.py | 23 ++++++++++------- src/cffi/api.py | 8 +++--- src/cffi/backend_ctypes.py | 8 ++++-- src/cffi/cparser.py | 6 +++-- src/cffi/ffiplatform.py | 3 ++- src/cffi/model.py | 2 +- src/cffi/pkgconfig.py | 4 ++- src/cffi/recompiler.py | 4 ++- src/cffi/vengine_gen.py | 3 ++- src/cffi/verifier.py | 6 ++++- testing/cffi0/backend_tests.py | 34 +++++++++++++++----------- testing/cffi0/callback_in_thread.py | 3 ++- testing/cffi0/test_ffi_backend.py | 9 ++++--- testing/cffi0/test_function.py | 4 ++- testing/cffi0/test_ownlib.py | 6 +++-- testing/cffi0/test_parsing.py | 3 ++- testing/cffi0/test_unicode_literals.py | 3 ++- testing/cffi0/test_verify.py | 14 ++++++++--- testing/cffi0/test_version.py | 6 +++-- testing/cffi0/test_zdistutils.py | 5 +++- testing/cffi0/test_zintegration.py | 7 ++++-- testing/cffi1/test_cffi_binary.py | 3 ++- testing/cffi1/test_commontypes.py | 4 ++- testing/cffi1/test_ffi_obj.py | 3 ++- testing/cffi1/test_function_args.py | 6 +++-- testing/cffi1/test_new_ffi_1.py | 31 +++++++++++++---------- testing/cffi1/test_parse_c_type.py | 4 ++- testing/cffi1/test_re_python.py | 3 ++- testing/cffi1/test_recompiler.py | 13 +++++----- testing/cffi1/test_verify1.py | 13 +++++++--- testing/cffi1/test_zdist.py | 5 ++-- testing/embedding/test_basic.py | 8 ++++-- testing/embedding/withunicode.py | 3 ++- testing/support.py | 3 ++- testing/udir.py | 4 ++- 42 files changed, 192 insertions(+), 103 deletions(-) diff --git a/demo/cffi-cocoa.py b/demo/cffi-cocoa.py index 9e86d990d..e21732f56 100644 --- a/demo/cffi-cocoa.py +++ b/demo/cffi-cocoa.py @@ -60,14 +60,14 @@ NSTitledWindowMask = ffi.cast('NSUInteger', 1) NSBackingStoreBuffered = ffi.cast('NSBackingStoreType', 2) -NSMakePoint = lambda x, y: ffi.new('NSPoint *', (x, y))[0] -NSMakeRect = lambda x, y, w, h: ffi.new('NSRect *', ((x, y), (w, h)))[0] +def NSMakePoint(x, y): + return ffi.new('NSPoint *', (x, y))[0] +def NSMakeRect(x, y, w, h): + return ffi.new('NSRect *', ((x, y), (w, h)))[0] get, send, sel = objc.objc_getClass, objc.objc_msgSend, objc.sel_registerName -at = lambda s: send( - get('NSString'), - sel('stringWithCString:encoding:'), - ffi.new('char[]', s), NSASCIIStringEncoding) +def at(s): + return send(get('NSString'), sel('stringWithCString:encoding:'), ffi.new('char[]', s), NSASCIIStringEncoding) send(get('NSAutoreleasePool'), sel('new')) app = send(get('NSApplication'), sel('sharedApplication')) diff --git a/demo/pwuid.py b/demo/pwuid.py index 7651e6e0a..c5f596c86 100644 --- a/demo/pwuid.py +++ b/demo/pwuid.py @@ -1,5 +1,6 @@ from __future__ import print_function -import sys, os +import sys +import os # run pwuid_build first, then make sure the shared object is on sys.path from _pwuid_cffi import ffi, lib diff --git a/demo/winclipboard.py b/demo/winclipboard.py index e7335e45e..68b2b90c1 100644 --- a/demo/winclipboard.py +++ b/demo/winclipboard.py @@ -1,7 +1,8 @@ from __future__ import print_function __author__ = "Israel Fruchter " -import sys, os +import sys +import os if not sys.platform == 'win32': raise Exception("Windows-only demo") diff --git a/demo/xclient.py b/demo/xclient.py index e4b3dd2d4..7b4af7c14 100644 --- a/demo/xclient.py +++ b/demo/xclient.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os # run xclient_build first, then make sure the shared object is on sys.path from _xclient_cffi import ffi, lib diff --git a/doc/source/conf.py b/doc/source/conf.py index a6855d48b..718baec1b 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,7 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import sys +import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/setup.py b/setup.py index 486485950..d1cebc944 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ -import sys, os, platform +import sys +import os +import platform import subprocess import errno diff --git a/setup_base.py b/setup_base.py index 4cf6ea5cd..6a4b0bd84 100644 --- a/setup_base.py +++ b/setup_base.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os from setup import include_dirs, sources, libraries, define_macros diff --git a/src/c/test_c.py b/src/c/test_c.py index ced4f821f..551a133d9 100644 --- a/src/c/test_c.py +++ b/src/c/test_c.py @@ -18,7 +18,8 @@ pass def _setup_path(): - import os, sys + import os + import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) _setup_path() from _cffi_backend import * @@ -71,7 +72,8 @@ def _capture_unraisable_hook(ur_args): mandatory_b_prefix = '' mandatory_u_prefix = 'u' bytechr = chr - bitem2bchr = lambda x: x + def bitem2bchr(x): + return x class U(object): def __add__(self, other): return eval('u'+repr(other).replace(r'\\u', r'\u') @@ -86,10 +88,12 @@ def __add__(self, other): unichr = chr mandatory_b_prefix = 'b' mandatory_u_prefix = '' - bytechr = lambda n: bytes([n]) + def bytechr(n): + return bytes([n]) bitem2bchr = bytechr u = "" - str2bytes = lambda s: bytes(s, "ascii") + def str2bytes(s): + return bytes(s, 'ascii') strict_compare = True def size_of_int(): @@ -457,7 +461,7 @@ def test_reading_pointer_to_pointer(): assert p[0] is not None assert p[0] == cast(BVoidP, 0) assert p[0] == cast(BCharP, 0) - assert p[0] != None + assert p[0] is not None assert repr(p[0]) == "" p[0] = q assert p[0] != cast(BVoidP, 0) @@ -492,12 +496,12 @@ def test_no_len_on_nonarray(): def test_cmp_none(): p = new_primitive_type("int") x = cast(p, 42) - assert (x == None) is False - assert (x != None) is True + assert (x is None) is False + assert (x is not None) is True assert (x == ["hello"]) is False assert (x != ["hello"]) is True y = cast(p, 0) - assert (y == None) is False + assert (y is None) is False def test_invalid_indexing(): p = new_primitive_type("int") @@ -2988,7 +2992,8 @@ def test_string_assignment_to_byte_array(): # XXX hack if sys.version_info >= (3,): try: - import posix, io + import posix + import io posix.fdopen = io.open except ImportError: pass # win32 diff --git a/src/cffi/api.py b/src/cffi/api.py index edeb79281..326b07286 100644 --- a/src/cffi/api.py +++ b/src/cffi/api.py @@ -1,4 +1,5 @@ -import sys, types +import sys +import types from .lock import allocate_lock from .error import CDefError from . import model @@ -8,7 +9,8 @@ except NameError: # Python 3.1 from collections import Callable - callable = lambda x: isinstance(x, Callable) + def callable(x): + return isinstance(x, Callable) try: basestring @@ -414,7 +416,7 @@ def getctype(self, cdecl, replace_with=''): if (replace_with.startswith('*') and '&[' in self._backend.getcname(cdecl, '&')): replace_with = '(%s)' % replace_with - elif replace_with and not replace_with[0] in '[(': + elif replace_with and replace_with[0] not in '[(': replace_with = ' ' + replace_with return self._backend.getcname(cdecl, replace_with) diff --git a/src/cffi/backend_ctypes.py b/src/cffi/backend_ctypes.py index e7956a79c..8534940e3 100644 --- a/src/cffi/backend_ctypes.py +++ b/src/cffi/backend_ctypes.py @@ -1,4 +1,7 @@ -import ctypes, ctypes.util, operator, sys +import ctypes +import ctypes.util +import operator +import sys from . import model if sys.version_info < (3,): @@ -7,7 +10,8 @@ unicode = str long = int xrange = range - bytechr = lambda num: bytes([num]) + def bytechr(num): + return bytes([num]) class CTypesType(type): pass diff --git a/src/cffi/cparser.py b/src/cffi/cparser.py index dd590d874..4ac2487fd 100644 --- a/src/cffi/cparser.py +++ b/src/cffi/cparser.py @@ -5,7 +5,9 @@ from . import _pycparser as pycparser except ImportError: import pycparser -import weakref, re, sys +import weakref +import re +import sys try: if sys.version_info < (3,): @@ -370,7 +372,7 @@ def convert_pycparser_error(self, e, csource): def parse(self, csource, override=False, packed=False, pack=None, dllexport=False): if packed: - if packed != True: + if packed is not True: raise ValueError("'packed' should be False or True; use " "'pack' to give another value") if pack: diff --git a/src/cffi/ffiplatform.py b/src/cffi/ffiplatform.py index adca28f1a..3e7a99879 100644 --- a/src/cffi/ffiplatform.py +++ b/src/cffi/ffiplatform.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os from .error import VerificationError diff --git a/src/cffi/model.py b/src/cffi/model.py index e5f4cae3e..3eb7a162b 100644 --- a/src/cffi/model.py +++ b/src/cffi/model.py @@ -34,7 +34,7 @@ def get_c_name(self, replace_with='', context='a C file', quals=0): if replace_with: if replace_with.startswith('*') and '&[' in result: replace_with = '(%s)' % replace_with - elif not replace_with[0] in '[(': + elif replace_with[0] not in '[(': replace_with = ' ' + replace_with replace_with = qualify(quals, replace_with) result = result.replace('&', replace_with) diff --git a/src/cffi/pkgconfig.py b/src/cffi/pkgconfig.py index 5c93f15a6..08901bc0d 100644 --- a/src/cffi/pkgconfig.py +++ b/src/cffi/pkgconfig.py @@ -1,5 +1,7 @@ # pkg-config, https://www.freedesktop.org/wiki/Software/pkg-config/ integration for cffi -import sys, os, subprocess +import sys +import os +import subprocess from .error import PkgConfigError diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index 14d578ee3..dc9c2e1f9 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -1,4 +1,6 @@ -import os, sys, io +import os +import sys +import io from . import ffiplatform, model from .error import VerificationError from .cffi_opcode import * diff --git a/src/cffi/vengine_gen.py b/src/cffi/vengine_gen.py index bffc82122..9eb9903e4 100644 --- a/src/cffi/vengine_gen.py +++ b/src/cffi/vengine_gen.py @@ -1,7 +1,8 @@ # # DEPRECATED: implementation for ffi.verify() # -import sys, os +import sys +import os import types from . import model diff --git a/src/cffi/verifier.py b/src/cffi/verifier.py index e392a2b7f..4415f2ec3 100644 --- a/src/cffi/verifier.py +++ b/src/cffi/verifier.py @@ -1,7 +1,11 @@ # # DEPRECATED: implementation for ffi.verify() # -import sys, os, binascii, shutil, io +import sys +import os +import binascii +import shutil +import io from . import __version_verifier_modules__ from . import ffiplatform from .error import VerificationError diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py index aed1b9c30..c5b3cc029 100644 --- a/testing/cffi0/backend_tests.py +++ b/testing/cffi0/backend_tests.py @@ -1,6 +1,8 @@ import pytest import platform -import sys, ctypes, ctypes.util +import sys +import ctypes +import ctypes.util from cffi import FFI, CDefError, FFIError, VerificationMissing from testing.support import * @@ -197,7 +199,7 @@ def test_pointer_direct(self): assert p is not None assert bool(p) is False assert p == ffi.cast("int*", 0) - assert p != None + assert p is not None assert repr(p) == "" a = ffi.new("int[]", [123, 456]) p = ffi.cast("int*", a) @@ -387,7 +389,7 @@ def test_none_as_null_doesnt_work(self): ffi = FFI(backend=self.Backend()) p = ffi.new("int*[1]") assert p[0] is not None - assert p[0] != None + assert p[0] is not None assert p[0] == ffi.NULL assert repr(p[0]) == "" # @@ -1144,14 +1146,14 @@ def test_pointer_comparison(self): assert (p > q) is False assert (p >= q) is False # - assert (None == s) is False - assert (None != s) is True - assert (s == None) is False - assert (s != None) is True - assert (None == q) is False - assert (None != q) is True - assert (q == None) is False - assert (q != None) is True + assert (None is s) is False + assert (None is not s) is True + assert (s is None) is False + assert (s is not None) is True + assert (None is q) is False + assert (None is not q) is True + assert (q is None) is False + assert (q is not None) is True def test_integer_comparison(self): ffi = FFI(backend=self.Backend()) @@ -1230,7 +1232,9 @@ def test_ffi_buffer_array_size(self): def test_ffi_buffer_with_file(self): ffi = FFI(backend=self.Backend()) - import tempfile, os, array + import tempfile + import os + import array fd, filename = tempfile.mkstemp() f = os.fdopen(fd, 'r+b') a = ffi.new("int[]", list(range(1005))) @@ -1250,7 +1254,8 @@ def test_ffi_buffer_with_file(self): def test_ffi_buffer_with_io(self): ffi = FFI(backend=self.Backend()) - import io, array + import io + import array f = io.BytesIO() a = ffi.new("int[]", list(range(1005))) try: @@ -1957,7 +1962,8 @@ def do_init(): assert seen == [1, 1] def test_init_once_multithread(self): - import sys, time + import sys + import time if sys.version_info < (3,): import thread else: diff --git a/testing/cffi0/callback_in_thread.py b/testing/cffi0/callback_in_thread.py index c98605c5e..f0f7bd5aa 100644 --- a/testing/cffi0/callback_in_thread.py +++ b/testing/cffi0/callback_in_thread.py @@ -1,4 +1,5 @@ -import sys, time +import sys +import time sys.path.insert(0, sys.argv[1]) from cffi import FFI diff --git a/testing/cffi0/test_ffi_backend.py b/testing/cffi0/test_ffi_backend.py index 399fb777d..345eaf8fd 100644 --- a/testing/cffi0/test_ffi_backend.py +++ b/testing/cffi0/test_ffi_backend.py @@ -1,4 +1,5 @@ -import sys, platform +import sys +import platform import pytest from testing.cffi0 import backend_tests, test_function, test_ownlib from testing.support import u @@ -160,7 +161,8 @@ def test_bogus_struct_containing_struct_containing_array_varsize(self): assert p.foo.data[3] != 78 # has been overwritten with 9999999 def test_issue553(self): - import gc, warnings + import gc + import warnings ffi = FFI(backend=self.Backend()) p = ffi.new("int *", 123) with warnings.catch_warnings(record=True) as w: @@ -169,7 +171,8 @@ def test_issue553(self): assert w == [] def test_issue553_from_buffer(self): - import gc, warnings + import gc + import warnings ffi = FFI(backend=self.Backend()) buf = b"123" with warnings.catch_warnings(record=True) as w: diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py index 6e741575f..10b0405b8 100644 --- a/testing/cffi0/test_function.py +++ b/testing/cffi0/test_function.py @@ -1,6 +1,8 @@ import pytest from cffi import FFI, CDefError -import math, os, sys +import math +import os +import sys import ctypes.util from cffi.backend_ctypes import CTypesBackend from testing.udir import udir diff --git a/testing/cffi0/test_ownlib.py b/testing/cffi0/test_ownlib.py index e1a61d672..9403cfbee 100644 --- a/testing/cffi0/test_ownlib.py +++ b/testing/cffi0/test_ownlib.py @@ -1,5 +1,7 @@ -import sys, os -import subprocess, weakref +import sys +import os +import subprocess +import weakref import pytest from cffi import FFI from cffi.backend_ctypes import CTypesBackend diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py index f10b989a1..6e74b0bae 100644 --- a/testing/cffi0/test_parsing.py +++ b/testing/cffi0/test_parsing.py @@ -1,4 +1,5 @@ -import sys, re +import sys +import re import pytest from cffi import FFI, FFIError, CDefError, VerificationError from .backend_tests import needs_dlopen_none diff --git a/testing/cffi0/test_unicode_literals.py b/testing/cffi0/test_unicode_literals.py index 8838de5cc..19afb9ad6 100644 --- a/testing/cffi0/test_unicode_literals.py +++ b/testing/cffi0/test_unicode_literals.py @@ -7,7 +7,8 @@ # # # -import sys, math +import sys +import math from cffi import FFI from testing.support import is_musl diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py index 4942bba6d..243be5a7e 100644 --- a/testing/cffi0/test_verify.py +++ b/testing/cffi0/test_verify.py @@ -1,6 +1,9 @@ import re import pytest -import sys, os, math, weakref +import sys +import os +import math +import weakref from cffi import FFI, VerificationError, VerificationMissing, model, FFIError from testing.support import * from testing.support import extra_compile_args, is_musl @@ -1424,7 +1427,8 @@ def test_ffi_struct_packed(): """) def test_tmpdir(): - import tempfile, os + import tempfile + import os from testing.udir import udir tmpdir = tempfile.mkdtemp(dir=str(udir)) ffi = FFI() @@ -1434,7 +1438,8 @@ def test_tmpdir(): assert lib.foo(100) == 142 def test_relative_to(): - import tempfile, os + import tempfile + import os from testing.udir import udir tmpdir = tempfile.mkdtemp(dir=str(udir)) ffi = FFI() @@ -1599,7 +1604,8 @@ def test_addressof(): def test_callback_in_thread(): if sys.platform == 'win32': pytest.skip("pthread only") - import os, subprocess + import os + import subprocess from cffi import _imp_emulation as imp arg = os.path.join(os.path.dirname(__file__), 'callback_in_thread.py') g = subprocess.Popen([sys.executable, arg, diff --git a/testing/cffi0/test_version.py b/testing/cffi0/test_version.py index 41cca9329..41f759444 100644 --- a/testing/cffi0/test_version.py +++ b/testing/cffi0/test_version.py @@ -1,6 +1,8 @@ -import os, sys +import os +import sys import pytest -import cffi, _cffi_backend +import cffi +import _cffi_backend from pathlib import Path def setup_module(mod): diff --git a/testing/cffi0/test_zdistutils.py b/testing/cffi0/test_zdistutils.py index 08c432c70..e0671d975 100644 --- a/testing/cffi0/test_zdistutils.py +++ b/testing/cffi0/test_zdistutils.py @@ -1,4 +1,7 @@ -import sys, os, math, shutil +import sys +import os +import math +import shutil import pytest from cffi import FFI, FFIError from cffi.verifier import Verifier, _locate_engine_class, _get_so_suffixes diff --git a/testing/cffi0/test_zintegration.py b/testing/cffi0/test_zintegration.py index 9fbbd91cb..c5562cfb7 100644 --- a/testing/cffi0/test_zintegration.py +++ b/testing/cffi0/test_zintegration.py @@ -1,4 +1,7 @@ -import py, os, sys, shutil +import py +import os +import sys +import shutil import subprocess import textwrap from testing.udir import udir @@ -189,7 +192,7 @@ def test_set_py_limited_api(self): setuptools.__version__ = '25.0' kwds = _set_py_limited_api(Extension, {}) - assert kwds.get('py_limited_api', False) == False + assert kwds.get('py_limited_api', False) is False setuptools.__version__ = 'development' kwds = _set_py_limited_api(Extension, {}) diff --git a/testing/cffi1/test_cffi_binary.py b/testing/cffi1/test_cffi_binary.py index 2fb042cee..fa68c103f 100644 --- a/testing/cffi1/test_cffi_binary.py +++ b/testing/cffi1/test_cffi_binary.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os import pytest import _cffi_backend from testing.support import is_musl diff --git a/testing/cffi1/test_commontypes.py b/testing/cffi1/test_commontypes.py index 9e7d79e9a..ed582fcbf 100644 --- a/testing/cffi1/test_commontypes.py +++ b/testing/cffi1/test_commontypes.py @@ -1,4 +1,6 @@ -import os, cffi, re +import os +import cffi +import re import pytest import _cffi_backend diff --git a/testing/cffi1/test_ffi_obj.py b/testing/cffi1/test_ffi_obj.py index 9b1532b8d..d1624bb75 100644 --- a/testing/cffi1/test_ffi_obj.py +++ b/testing/cffi1/test_ffi_obj.py @@ -33,7 +33,8 @@ def test_ffi_cache_type(): assert ffi.typeof("int(*)()") is ffi.typeof("int(*)()") def test_ffi_type_not_immortal(): - import weakref, gc + import weakref + import gc ffi = _cffi1_backend.FFI() t1 = ffi.typeof("int **") t2 = ffi.typeof("int *") diff --git a/testing/cffi1/test_function_args.py b/testing/cffi1/test_function_args.py index 30c6fedae..f15015d79 100644 --- a/testing/cffi1/test_function_args.py +++ b/testing/cffi1/test_function_args.py @@ -1,4 +1,5 @@ -import pytest, sys +import pytest +import sys try: # comment out the following line to run this test. # the latest on x86-64 linux: https://github.com/libffi/libffi/issues/574 @@ -15,7 +16,8 @@ def test_types(): else: from cffi import FFI - import sys, random + import sys + import random from .test_recompiler import verify ALL_PRIMITIVES = [ diff --git a/testing/cffi1/test_new_ffi_1.py b/testing/cffi1/test_new_ffi_1.py index 061e21633..915857138 100644 --- a/testing/cffi1/test_new_ffi_1.py +++ b/testing/cffi1/test_new_ffi_1.py @@ -1,6 +1,8 @@ import pytest import platform -import sys, os, ctypes +import sys +import os +import ctypes import cffi from testing.udir import udir from testing.support import * @@ -265,7 +267,7 @@ def test_pointer_direct(self): assert p is not None assert bool(p) is False assert p == ffi.cast("int*", 0) - assert p != None + assert p is not None assert repr(p) == "" a = ffi.new("int[]", [123, 456]) p = ffi.cast("int*", a) @@ -446,7 +448,7 @@ def test_wchar_t(self): def test_none_as_null_doesnt_work(self): p = ffi.new("int*[1]") assert p[0] is not None - assert p[0] != None + assert p[0] is not None assert p[0] == ffi.NULL assert repr(p[0]) == "" # @@ -1130,14 +1132,14 @@ def test_pointer_comparison(self): assert (p > q) is False assert (p >= q) is False # - assert (None == s) is False - assert (None != s) is True - assert (s == None) is False - assert (s != None) is True - assert (None == q) is False - assert (None != q) is True - assert (q == None) is False - assert (q != None) is True + assert (None is s) is False + assert (None is not s) is True + assert (s is None) is False + assert (s is not None) is True + assert (None is q) is False + assert (None is not q) is True + assert (q is None) is False + assert (q is not None) is True def test_integer_comparison(self): x = ffi.cast("int", 123) @@ -1209,7 +1211,9 @@ def test_ffi_buffer_array_size(self): assert ffi.buffer(a1)[:] == ffi.buffer(a2, 4*10)[:] def test_ffi_buffer_with_file(self): - import tempfile, os, array + import tempfile + import os + import array fd, filename = tempfile.mkstemp() f = os.fdopen(fd, 'r+b') a = ffi.new("int[]", list(range(1005))) @@ -1228,7 +1232,8 @@ def test_ffi_buffer_with_file(self): os.unlink(filename) def test_ffi_buffer_with_io(self): - import io, array + import io + import array f = io.BytesIO() a = ffi.new("int[]", list(range(1005))) try: diff --git a/testing/cffi1/test_parse_c_type.py b/testing/cffi1/test_parse_c_type.py index d203ba837..a071fb31a 100644 --- a/testing/cffi1/test_parse_c_type.py +++ b/testing/cffi1/test_parse_c_type.py @@ -1,4 +1,6 @@ -import sys, re, os +import sys +import re +import os import pytest import cffi from cffi import cffi_opcode diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py index fdf083ac2..ef9db6219 100644 --- a/testing/cffi1/test_re_python.py +++ b/testing/cffi1/test_re_python.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os import pytest from cffi import FFI from cffi import recompiler, ffiplatform, VerificationMissing diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py index f36512a3d..c371b8429 100644 --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -1,5 +1,6 @@ -import sys, os +import sys +import os import pytest from cffi import FFI, VerificationError, FFIError, CDefError from cffi import recompiler @@ -2045,7 +2046,7 @@ def test_function_returns_partial_struct(): def test_function_returns_float_complex(): ffi = FFI() - ffi.cdef("float _Complex f1(float a, float b);"); + ffi.cdef("float _Complex f1(float a, float b);") if sys.platform == 'win32': lib = verify(ffi, "test_function_returns_float_complex", """ #include @@ -2063,7 +2064,7 @@ def test_function_returns_float_complex(): def test_function_returns_double_complex(): ffi = FFI() - ffi.cdef("double _Complex f1(double a, double b);"); + ffi.cdef("double _Complex f1(double a, double b);") if sys.platform == 'win32': lib = verify(ffi, "test_function_returns_double_complex", """ #include @@ -2083,7 +2084,7 @@ def test_cdef_using_windows_complex(): if sys.platform != 'win32': pytest.skip("only for MSVC") ffi = FFI() - ffi.cdef("_Fcomplex f1(float a, float b); _Dcomplex f2(double a, double b);"); + ffi.cdef("_Fcomplex f1(float a, float b); _Dcomplex f2(double a, double b);") lib = verify(ffi, "test_cdef_using_windows_complex", """ #include static _Fcomplex f1(float a, float b) { return _FCbuild(a, 2.0f*b); } @@ -2100,7 +2101,7 @@ def test_cdef_using_windows_complex(): def test_function_argument_float_complex(): ffi = FFI() - ffi.cdef("float f1(float _Complex x);"); + ffi.cdef("float f1(float _Complex x);") if sys.platform == 'win32': lib = verify(ffi, "test_function_argument_float_complex", """ #include @@ -2117,7 +2118,7 @@ def test_function_argument_float_complex(): def test_function_argument_double_complex(): ffi = FFI() - ffi.cdef("double f1(double _Complex);"); + ffi.cdef("double f1(double _Complex);") if sys.platform == 'win32': lib = verify(ffi, "test_function_argument_double_complex", """ #include diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py index a7ac14d3d..6df98d336 100644 --- a/testing/cffi1/test_verify1.py +++ b/testing/cffi1/test_verify1.py @@ -1,4 +1,6 @@ -import os, sys, math +import os +import sys +import math import pytest from cffi import FFI, FFIError, VerificationError, VerificationMissing, model from cffi import CDefError @@ -1390,7 +1392,8 @@ def test_ffi_struct_packed(): """) def test_tmpdir(): - import tempfile, os + import tempfile + import os from testing.udir import udir tmpdir = tempfile.mkdtemp(dir=str(udir)) ffi = FFI() @@ -1401,7 +1404,8 @@ def test_tmpdir(): def test_relative_to(): pytest.skip("not available") - import tempfile, os + import tempfile + import os from testing.udir import udir tmpdir = tempfile.mkdtemp(dir=str(udir)) ffi = FFI() @@ -1558,7 +1562,8 @@ def test_callback_in_thread(): pytest.xfail("adapt or remove") if sys.platform == 'win32': pytest.skip("pthread only") - import os, subprocess + import os + import subprocess from cffi import _imp_emulation as imp arg = os.path.join(os.path.dirname(__file__), 'callback_in_thread.py') g = subprocess.Popen([sys.executable, arg, diff --git a/testing/cffi1/test_zdist.py b/testing/cffi1/test_zdist.py index 9003f65d0..82c5bf0cc 100644 --- a/testing/cffi1/test_zdist.py +++ b/testing/cffi1/test_zdist.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os import pytest import subprocess import cffi @@ -39,7 +40,7 @@ def run(self, args, cwd=None): # NOTE: pointing $HOME to a nonexistent directory can break certain things # that look there for configuration (like ccache). tmp_home = mkdtemp() - assert tmp_home != None, "cannot create temporary homedir" + assert tmp_home is not None, "cannot create temporary homedir" env['HOME'] = tmp_home pathlist = sys.path[:] if cwd is None: diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py index 6743e1a4a..bf0316fc0 100644 --- a/testing/embedding/test_basic.py +++ b/testing/embedding/test_basic.py @@ -1,5 +1,9 @@ -import sys, os, re -import shutil, subprocess, time +import sys +import os +import re +import shutil +import subprocess +import time import pytest from testing.udir import udir import cffi diff --git a/testing/embedding/withunicode.py b/testing/embedding/withunicode.py index 839c6cdff..cc1b9b8ed 100644 --- a/testing/embedding/withunicode.py +++ b/testing/embedding/withunicode.py @@ -1,4 +1,5 @@ -import sys, cffi +import sys +import cffi if sys.version_info < (3,): u_prefix = "u" else: diff --git a/testing/support.py b/testing/support.py index 063e52cff..e62fa9faa 100644 --- a/testing/support.py +++ b/testing/support.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os from cffi._imp_emulation import load_dynamic if sys.version_info < (3,): diff --git a/testing/udir.py b/testing/udir.py index 59db1c4e9..98c47fce2 100644 --- a/testing/udir.py +++ b/testing/udir.py @@ -1,5 +1,7 @@ import py -import sys, os, atexit +import sys +import os +import atexit # This is copied from PyPy's vendored py lib. The latest py lib release