Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff check --select=E --fix --unsafe-fixes #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions demo/cffi-cocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
3 changes: 2 additions & 1 deletion demo/pwuid.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion demo/winclipboard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
__author__ = "Israel Fruchter <[email protected]>"

import sys, os
import sys
import os

if not sys.platform == 'win32':
raise Exception("Windows-only demo")
Expand Down
3 changes: 2 additions & 1 deletion demo/xclient.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sys, os, platform
import sys
import os
import platform
import subprocess
import errno

Expand Down
3 changes: 2 additions & 1 deletion setup_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, os
import sys
import os


from setup import include_dirs, sources, libraries, define_macros
Expand Down
23 changes: 14 additions & 9 deletions src/c/test_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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')
Expand All @@ -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():
Expand Down Expand Up @@ -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]) == "<cdata 'int *' NULL>"
p[0] = q
assert p[0] != cast(BVoidP, 0)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/cffi/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, types
import sys
import types
from .lock import allocate_lock
from .error import CDefError
from . import model
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions src/cffi/backend_ctypes.py
Original file line number Diff line number Diff line change
@@ -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,):
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/cffi/cparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,):
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/cffi/ffiplatform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, os
import sys
import os
from .error import VerificationError


Expand Down
2 changes: 1 addition & 1 deletion src/cffi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/cffi/pkgconfig.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/cffi/recompiler.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down
3 changes: 2 additions & 1 deletion src/cffi/vengine_gen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# DEPRECATED: implementation for ffi.verify()
#
import sys, os
import sys
import os
import types

from . import model
Expand Down
6 changes: 5 additions & 1 deletion src/cffi/verifier.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 20 additions & 14 deletions testing/cffi0/backend_tests.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -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) == "<cdata 'int *' NULL>"
a = ffi.new("int[]", [123, 456])
p = ffi.cast("int*", a)
Expand Down Expand Up @@ -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]) == "<cdata 'int *' NULL>"
#
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)))
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion testing/cffi0/callback_in_thread.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, time
import sys
import time
sys.path.insert(0, sys.argv[1])
from cffi import FFI

Expand Down
9 changes: 6 additions & 3 deletions testing/cffi0/test_ffi_backend.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion testing/cffi0/test_function.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions testing/cffi0/test_ownlib.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading
Loading