Skip to content
Merged
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
8 changes: 0 additions & 8 deletions demo/_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,14 @@ def bkgdset(self, ch, attr=None):
if attr is None:
attr = lib.A_NORMAL
lib.wbkgdset(self._win, _chtype(ch) | attr)
return None

def border(self, ls=0, rs=0, ts=0, bs=0, tl=0, tr=0, bl=0, br=0):
lib.wborder(self._win,
_chtype(ls), _chtype(rs), _chtype(ts), _chtype(bs),
_chtype(tl), _chtype(tr), _chtype(bl), _chtype(br))
return None

def box(self, vertint=0, horint=0):
lib.box(self._win, vertint, horint)
return None

@_argspec(1, 1, 2)
def chgat(self, y, x, num, attr=None):
Expand Down Expand Up @@ -650,7 +647,6 @@ def vline(self, y, x, ch, n, attr=None):

def filter():
lib.filter()
return None


def color_content(color):
Expand Down Expand Up @@ -913,7 +909,6 @@ def qiflush(flag=True):
lib.qiflush()
else:
lib.noqiflush()
return None


# XXX: Do something about the following?
Expand Down Expand Up @@ -1016,15 +1011,13 @@ def qiflush(flag=True):
def setsyx(y, x):
_ensure_initialised()
lib.setsyx(y, x)
return None


def start_color():
_check_ERR(lib.start_color(), "start_color")
globals()["COLORS"] = lib.COLORS
globals()["COLOR_PAIRS"] = lib.COLOR_PAIRS
globals()["_initialised_color"] = True
return None


def tigetflag(capname):
Expand Down Expand Up @@ -1070,7 +1063,6 @@ def ungetch(ch):

def use_env(flag):
lib.use_env(flag)
return None


if not lib._m_STRICT_SYSV_CURSES:
Expand Down
2 changes: 1 addition & 1 deletion demo/bsdopendirtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def opendir(dir):
raise _posix_error()
return
name = ffi.string(dirent.d_name)
if name == b'.' or name == b'..':
if name in {b'.', b'..'}:
continue
name = dirname + name
try:
Expand Down
2 changes: 1 addition & 1 deletion demo/readdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def walk(basefd, path):
break
name = ffi.string(dirent.d_name)
print('%3d %s' % (dirent.d_type, name))
if dirent.d_type == 4 and name != '.' and name != '..':
if dirent.d_type == 4 and name not in {'.', '..'}:
walk(dirfd, name)
lib.closedir(dir)
print('}')
Expand Down
2 changes: 1 addition & 1 deletion demo/readdir2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def walk(basefd, path):
break
name = ffi.string(dirent.d_name)
print('%3d %s' % (dirent.d_type, name))
if dirent.d_type == lib.DT_DIR and name != '.' and name != '..':
if dirent.d_type == lib.DT_DIR and name not in {'.', '..'}:
walk(dirfd, name)
lib.closedir(dir)
print('}')
Expand Down
2 changes: 1 addition & 1 deletion demo/readdir_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def walk(basefd, path):
break
name = dirent.d_name
print('%3d %s' % (dirent.d_type, name))
if dirent.d_type == 4 and name != '.' and name != '..':
if dirent.d_type == 4 and name not in {'.', '..'}:
walk(dirfd, name)
closedir(dir)
print('}')
Expand Down
2 changes: 1 addition & 1 deletion demo/recopendirtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def opendir(dir):
if result[0] == ffi.NULL:
return #
name = ffi.string(dirent.d_name)
if name == b'.' or name == b'..':
if name in {b'.', b'..'}:
continue
name = dirname + name
try:
Expand Down
15 changes: 7 additions & 8 deletions src/c/test_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -3366,15 +3366,14 @@ def _test_bitfield_details(flag):
assert raw == b'A\xE3\x9B\x9D'
else:
raise AssertionError("bad flag")
elif flag & SF_MSVC_BITFIELDS:
assert raw == b'A\x00\x00\x00\x00\x00\xC77\x9D\x00\x00\x00'
elif flag & SF_GCC_LITTLE_ENDIAN:
assert raw == b'A\xC77\x9D'
elif flag & SF_GCC_BIG_ENDIAN:
assert raw == b'A\x9B\xE3\x9D'
else:
if flag & SF_MSVC_BITFIELDS:
assert raw == b'A\x00\x00\x00\x00\x00\xC77\x9D\x00\x00\x00'
elif flag & SF_GCC_LITTLE_ENDIAN:
assert raw == b'A\xC77\x9D'
elif flag & SF_GCC_BIG_ENDIAN:
assert raw == b'A\x9B\xE3\x9D'
else:
raise AssertionError("bad flag")
raise AssertionError("bad flag")
#
BStruct = new_struct_type("struct foo2")
complete_struct_or_union(BStruct, [('a', BChar, -1),
Expand Down
11 changes: 5 additions & 6 deletions src/cffi/backend_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def _to_ctypes(novalue):
if novalue is not None:
raise TypeError("None expected, got %s object" %
(type(novalue).__name__,))
return None
CTypesVoid._fix_class()
return CTypesVoid

Expand Down Expand Up @@ -387,7 +386,7 @@ def _create_ctype_obj(init):
return ctype()
return ctype(CTypesPrimitive._to_ctypes(init))

if kind == 'int' or kind == 'byte':
if kind in {'int', 'byte'}:
@classmethod
def _cast_from(cls, source):
source = _cast_source_to_int(source)
Expand Down Expand Up @@ -435,7 +434,7 @@ def __float__(self):

_cast_to_integer = __int__

if kind == 'int' or kind == 'byte' or kind == 'bool':
if kind in {'int', 'byte', 'bool'}:
@staticmethod
def _to_ctypes(x):
if not isinstance(x, (int, long)):
Expand Down Expand Up @@ -558,15 +557,15 @@ def __getitem__(self, index):
def __setitem__(self, index, value):
self._as_ctype_ptr[index] = BItem._to_ctypes(value)

if kind == 'charp' or kind == 'voidp':
if kind in {'charp', 'voidp'}:
@classmethod
def _arg_to_ctypes(cls, *value):
if value and isinstance(value[0], bytes):
return ctypes.c_char_p(value[0])
else:
return super()._arg_to_ctypes(*value)

if kind == 'charp' or kind == 'bytep':
if kind in {'charp', 'bytep'}:
def _to_string(self, maxlen):
if maxlen < 0:
maxlen = sys.maxsize
Expand Down Expand Up @@ -663,7 +662,7 @@ def __setitem__(self, index, value):
raise IndexError
self._blob[index] = BItem._to_ctypes(value)

if kind == 'char' or kind == 'byte':
if kind in {'char', 'byte'}:
def _to_string(self, maxlen):
if maxlen < 0:
maxlen = len(self._blob)
Expand Down
9 changes: 4 additions & 5 deletions src/cffi/cparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,10 @@ def _get_struct_union_enum_type(self, kind, type, name=None, nested=False):
raise AssertionError("kind = %r" % (kind,))
if name is not None:
self._declare(key, tp)
else:
if kind == 'enum' and type.values is not None:
raise NotImplementedError(
"enum %s: the '{}' declaration should appear on the first "
"time the enum is mentioned, not later" % explicit_name)
elif kind == 'enum' and type.values is not None:
raise NotImplementedError(
"enum %s: the '{}' declaration should appear on the first "
"time the enum is mentioned, not later" % explicit_name)
if not tp.forcename:
tp.force_the_name(force_name)
if tp.forcename and '$' in tp.name:
Expand Down
2 changes: 1 addition & 1 deletion testing/cffi0/backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_integer_ranges(self):
c_decl = {None: '',
False: 'signed ',
True: 'unsigned '}[unsigned] + c_type
if c_decl == 'char' or c_decl == '':
if c_decl in {'char', ''}:
continue
self._test_int_type(ffi, c_decl, size, unsigned)

Expand Down
6 changes: 3 additions & 3 deletions testing/cffi0/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_all_integer_and_float_types():
for typename in all_primitive_types:
if (all_primitive_types[typename] == 'c' or
all_primitive_types[typename] == 'j' or # complex
typename == '_Bool' or typename == 'long double'):
typename in {'_Bool', 'long double'}):
pass
else:
typenames.append(typename)
Expand Down Expand Up @@ -1665,7 +1665,7 @@ def test_FILE_stored_in_stdout():
os.close(fdr)
# the 'X' might remain in the user-level buffer of 'fw1' and
# end up showing up after the 'hello, 42!\n'
assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
assert result in {b"Xhello, 42!\n", b"hello, 42!\nX"}

def test_FILE_stored_explicitly():
ffi = FFI()
Expand All @@ -1691,7 +1691,7 @@ def test_FILE_stored_explicitly():
os.close(fdr)
# the 'X' might remain in the user-level buffer of 'fw1' and
# end up showing up after the 'hello, 42!\n'
assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
assert result in {b"Xhello, 42!\n", b"hello, 42!\nX"}

def test_global_array_with_missing_length():
ffi = FFI()
Expand Down
5 changes: 2 additions & 3 deletions testing/cffi0/test_zdistutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def test_locate_engine_class(self):
# asked for the generic engine, which must not generate a
# CPython extension module
assert not cls._gen_python_module
else:
elif '__pypy__' not in sys.builtin_module_names:
# asked for the CPython engine: check that we got it, unless
# we are running on top of PyPy, where the generic engine is
# always better
if '__pypy__' not in sys.builtin_module_names:
assert cls._gen_python_module
assert cls._gen_python_module

def test_write_source(self):
ffi = FFI()
Expand Down
4 changes: 2 additions & 2 deletions testing/cffi1/test_ffi_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ def myfree(raw):
retries += 1
assert retries <= 5
import gc; gc.collect()
assert (seen == [40, 40, raw1, raw2] or
seen == [40, 40, raw2, raw1])
assert seen in ([40, 40, raw1, raw2],
[40, 40, raw2, raw1])
assert repr(seen[2]) == "<cdata 'char[]' owning 41 bytes>"
assert repr(seen[3]) == "<cdata 'char[]' owning 41 bytes>"

Expand Down
7 changes: 3 additions & 4 deletions testing/cffi1/test_function_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ def check(p, v):
if type(v) is list:
for i, v1 in enumerate(v):
check(ffi.addressof(p, 'f%d' % i), v1)
elif ffi.typeof(p).item is _tp_long_double:
assert ffi.cast("double", p[0]) == v
else:
if ffi.typeof(p).item is _tp_long_double:
assert ffi.cast("double", p[0]) == v
else:
assert p[0] == v
assert p[0] == v

for i, arg in enumerate(passed_args):
check(ffi.addressof(lib, 'testfargs_arg%d' % i), arg)
Expand Down
2 changes: 1 addition & 1 deletion testing/cffi1/test_new_ffi_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_integer_ranges(self):
c_decl = {None: '',
False: 'signed ',
True: 'unsigned '}[unsigned] + c_type
if c_decl == 'char' or c_decl == '':
if c_decl in {'char', ''}:
continue
self._test_int_type(ffi, c_decl, size, unsigned)

Expand Down
2 changes: 1 addition & 1 deletion testing/cffi1/test_pkgconfig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import subprocess
import pytest
import cffi.pkgconfig as pkgconfig
from cffi import pkgconfig
from cffi import PkgConfigError


Expand Down
6 changes: 3 additions & 3 deletions testing/cffi1/test_verify1.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_all_integer_and_float_types():
for typename in all_primitive_types:
if (all_primitive_types[typename] == 'c' or
all_primitive_types[typename] == 'j' or # complex
typename == '_Bool' or typename == 'long double'):
typename in {'_Bool', 'long double'}):
pass
else:
typenames.append(typename)
Expand Down Expand Up @@ -1629,7 +1629,7 @@ def test_FILE_stored_in_stdout():
os.close(fdr)
# the 'X' might remain in the user-level buffer of 'fw1' and
# end up showing up after the 'hello, 42!\n'
assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
assert result in {b"Xhello, 42!\n", b"hello, 42!\nX"}

def test_FILE_stored_explicitly():
ffi = FFI()
Expand All @@ -1655,7 +1655,7 @@ def test_FILE_stored_explicitly():
os.close(fdr)
# the 'X' might remain in the user-level buffer of 'fw1' and
# end up showing up after the 'hello, 42!\n'
assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
assert result in {b"Xhello, 42!\n", b"hello, 42!\nX"}

def test_global_array_with_missing_length():
ffi = FFI()
Expand Down
25 changes: 12 additions & 13 deletions testing/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ def typeof_disabled(*args, **kwds):

if sys.platform == 'win32':
extra_compile_args = [] # no obvious -Werror equivalent on MSVC
elif (sys.platform == 'darwin' and
[int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]):
# assume a standard clang or gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter',
'-Wno-unreachable-code']
# special things for clang
extra_compile_args.append('-Qunused-arguments')
else:
if (sys.platform == 'darwin' and
[int(x) for x in os.uname()[2].split('.')] >= [11, 0, 0]):
# assume a standard clang or gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter',
'-Wno-unreachable-code']
# special things for clang
extra_compile_args.append('-Qunused-arguments')
else:
# assume a standard gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter',
'-Wno-unreachable-code']
# assume a standard gcc
extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
'-Wno-unused-parameter',
'-Wno-unreachable-code']

is_musl = False
if sys.platform == 'linux':
Expand Down
Loading