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
4 changes: 1 addition & 3 deletions demo/_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ def is_linetouched(self, line):
code = lib.is_linetouched(self._win, line)
if code == lib.ERR:
raise error("is_linetouched: line number outside of boundaries")
if code == lib.FALSE:
return False
return True
return code != lib.FALSE

def noutrefresh(self, *args):
if lib._m_ispad(self._win):
Expand Down
9 changes: 3 additions & 6 deletions src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,8 @@ def write_source_to_f(self, f, preamble):
self.write_c_source_to_f(f, preamble)

def _rel_readlines(self, filename):
g = open(os.path.join(os.path.dirname(__file__), filename), 'r')
lines = g.readlines()
g.close()
return lines
with open(os.path.join(os.path.dirname(__file__), filename), 'r') as g:
return g.readlines()

def write_c_source_to_f(self, f, preamble):
self._f = f
Expand Down Expand Up @@ -538,8 +536,7 @@ def _convert_funcarg_to_c(self, tp, fromvar, tovar, errcode):
tovar, errcode)
return
#
elif (isinstance(tp, model.StructOrUnionOrEnum) or
isinstance(tp, model.BasePrimitiveType)):
elif (isinstance(tp, (model.StructOrUnionOrEnum, model.BasePrimitiveType))):
# a struct (not a struct pointer) as a function argument;
# or, a complex (the same code works)
self._prnt(' if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)'
Expand Down
2 changes: 1 addition & 1 deletion src/cffi/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _write_source(self, file=None):
# Determine if this matches the current file
if os.path.exists(self.sourcefilename):
with open(self.sourcefilename, "r") as fp:
needs_written = not (fp.read() == source_data)
needs_written = fp.read() != source_data
else:
needs_written = True

Expand Down
10 changes: 4 additions & 6 deletions testing/cffi0/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def setup_module():
def _write_source_and_check(self, file=None):
base_write_source(self, file)
if file is None:
f = open(self.sourcefilename)
data = f.read()
f.close()
with open(self.sourcefilename) as f:
data = f.read()
data = _r_comment.sub(' ', data)
data = _r_string.sub('"skipped"', data)
assert '$' not in data
Expand Down Expand Up @@ -1440,9 +1439,8 @@ def test_relative_to():
tmpdir = tempfile.mkdtemp(dir=str(udir))
ffi = FFI()
ffi.cdef("int foo(int);")
f = open(os.path.join(tmpdir, 'foo.h'), 'w')
f.write("int foo(int a) { return a + 42; }\n")
f.close()
with open(os.path.join(tmpdir, 'foo.h'), 'w') as f:
f.write("int foo(int a) { return a + 42; }\n")
lib = ffi.verify('#include "foo.h"',
include_dirs=['.'],
relative_to=os.path.join(tmpdir, 'x'))
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 @@ -1811,7 +1811,7 @@ def test_import_from_lib(self):
# equivalent to "import ffi, lib"
d = {}
exec("from _test_import_from_lib import *", d)
assert (sorted([x for x in d.keys() if not x.startswith('__')]) ==
assert (sorted(x for x in d if not x.startswith('__')) ==
['ffi', 'lib'])

def test_char16_t(self):
Expand Down
5 changes: 2 additions & 3 deletions testing/cffi1/test_verify1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,8 @@ def test_relative_to():
tmpdir = tempfile.mkdtemp(dir=str(udir))
ffi = FFI()
ffi.cdef("int foo(int);")
f = open(os.path.join(tmpdir, 'foo.h'), 'w')
f.write("int foo(int a) { return a + 42; }\n")
f.close()
with open(os.path.join(tmpdir, 'foo.h'), 'w') as f:
f.write("int foo(int a) { return a + 42; }\n")
lib = ffi.verify('#include "foo.h"',
include_dirs=['.'],
relative_to=os.path.join(tmpdir, 'x'))
Expand Down
Loading