Skip to content
Open
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
2 changes: 1 addition & 1 deletion demo/_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class error(Exception):
pass


class Window(object):
class Window:
def __init__(self, window):
self._win = window

Expand Down
2 changes: 1 addition & 1 deletion demo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def verify(self, source='', **kwargs):
return lib


class _PyExport(object):
class _PyExport:
def __init__(self, tp, func):
self.tp = tp
self.func = func
Expand Down
4 changes: 1 addition & 3 deletions demo/btrfs-snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

creates a exactly named snapshots and bails out if they exist
"""
from __future__ import print_function

import argparse
import fcntl
import os
Expand Down Expand Up @@ -47,7 +45,7 @@
args_buffer = ffi.buffer(args)
try:
fcntl.ioctl(target, lib.BTRFS_IOC_SNAP_CREATE_V2, args_buffer)
except IOError as e:
except OSError as e:
print(e)
sys.exit(1)

1 change: 0 additions & 1 deletion demo/extern_python_varargs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import cffi

ffi = cffi.FFI()
Expand Down
1 change: 0 additions & 1 deletion demo/fastcsv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import csv
import cffi

Expand Down
1 change: 0 additions & 1 deletion demo/gmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys
#
# This is only a demo based on the GMP library.
Expand Down
1 change: 0 additions & 1 deletion demo/manual2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import _cffi_backend

ffi = _cffi_backend.FFI(b"manual2",
Expand Down
1 change: 0 additions & 1 deletion demo/pwuid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys, os

# run pwuid_build first, then make sure the shared object is on sys.path
Expand Down
4 changes: 1 addition & 3 deletions demo/pyobj.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

referents = [] # list "object descriptor -> python object"
freelist = None

Expand All @@ -24,7 +22,7 @@ def discard(p):
freelist = p
return x

class Ref(object):
class Ref:
"""For use in 'with Ref(x) as ob': open an object descriptor
and returns it in 'ob', and close it automatically when the
'with' statement finishes."""
Expand Down
1 change: 0 additions & 1 deletion demo/readdir.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
# A Linux-only demo
#
import sys
Expand Down
1 change: 0 additions & 1 deletion demo/readdir2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
# A Linux-only demo, using set_source() instead of hard-coding the exact layouts
#
import sys
Expand Down
1 change: 0 additions & 1 deletion demo/readdir_ctypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
# A Linux-only demo
#
# For comparison purposes, this is a ctypes version of readdir.py.
Expand Down
1 change: 0 additions & 1 deletion demo/winclipboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
__author__ = "Israel Fruchter <[email protected]>"

import sys, os
Expand Down
10 changes: 4 additions & 6 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# CFFI documentation build configuration file, created by
# sphinx-quickstart on Thu Jun 14 16:37:47 2012.
#
Expand Down Expand Up @@ -37,8 +35,8 @@
master_doc = 'index'

# General information about the project.
project = u'CFFI'
copyright = u'2012-2025, Armin Rigo, Maciej Fijalkowski'
project = 'CFFI'
copyright = '2012-2025, Armin Rigo, Maciej Fijalkowski'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -172,8 +170,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'CFFI.tex', u'CFFI Documentation',
u'Armin Rigo, Maciej Fijalkowski', 'manual'),
('index', 'CFFI.tex', 'CFFI Documentation',
'Armin Rigo, Maciej Fijalkowski', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
22 changes: 11 additions & 11 deletions src/c/test_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _capture_unraisable_hook(ur_args):
mandatory_u_prefix = 'u'
bytechr = chr
bitem2bchr = lambda x: x
class U(object):
class U:
def __add__(self, other):
return eval('u'+repr(other).replace(r'\\u', r'\u')
.replace(r'\\U', r'\U'))
Expand Down Expand Up @@ -460,7 +460,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 @@ -495,12 +495,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 @@ -3017,8 +3017,8 @@ def test_string_assignment_to_byte_array():
# XXX hack
if sys.version_info >= (3,):
try:
import posix, io
posix.fdopen = io.open
import posix
posix.fdopen = open
except ImportError:
pass # win32

Expand Down Expand Up @@ -3322,7 +3322,7 @@ def test_new_handle_cycle():
import gc
import _weakref
BVoidP = new_pointer_type(new_void_type())
class A(object):
class A:
pass
o = A()
o.cycle = newp_handle(BVoidP, o)
Expand Down Expand Up @@ -3849,7 +3849,7 @@ def check(methods, expected, expected_for_memoryview=None):
return
if expected_for_memoryview is not None:
expected = expected_for_memoryview
class X(object):
class X:
pass
_testbuff(X, methods)
bufobj = X()
Expand Down Expand Up @@ -4180,8 +4180,8 @@ def test_unpack():
for typename in ["wchar_t", "char16_t", "char32_t"]:
BWChar = new_primitive_type(typename)
BArray = new_array_type(new_pointer_type(BWChar), 10) # wchar_t[10]
p = newp(BArray, u"abc\x00def")
assert unpack(p, 10) == u"abc\x00def\x00\x00\x00"
p = newp(BArray, "abc\x00def")
assert unpack(p, 10) == "abc\x00def\x00\x00\x00"

for typename, samples in [
("uint8_t", [0, 2**8-1]),
Expand Down
13 changes: 3 additions & 10 deletions src/cffi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
from .error import CDefError
from . import model

try:
callable
except NameError:
# Python 3.1
from collections import Callable
callable = lambda x: isinstance(x, Callable)

try:
basestring
except NameError:
Expand All @@ -20,7 +13,7 @@



class FFI(object):
class FFI:
r'''
The main top-level class that you instantiate once, or once per module.

Expand Down Expand Up @@ -414,7 +407,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 Expand Up @@ -909,7 +902,7 @@ def make_accessor(name):
raise AttributeError(name)
accessors[name](name)
#
class FFILibrary(object):
class FFILibrary:
def __getattr__(self, name):
make_accessor(name)
return getattr(self, name)
Expand Down
14 changes: 7 additions & 7 deletions src/cffi/backend_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class CTypesType(type):
pass

class CTypesData(object):
class CTypesData:
__metaclass__ = CTypesType
__slots__ = ['__weakref__']
__name__ = '<cdata>'
Expand Down Expand Up @@ -270,7 +270,7 @@ def __repr__(self, c_name=None):
return CTypesData.__repr__(self, c_name or self._get_c_name(' &'))


class CTypesBackend(object):
class CTypesBackend:

PRIMITIVE_TYPES = {
'char': ctypes.c_char,
Expand Down Expand Up @@ -564,7 +564,7 @@ def _arg_to_ctypes(cls, *value):
if value and isinstance(value[0], bytes):
return ctypes.c_char_p(value[0])
else:
return super(CTypesPtr, cls)._arg_to_ctypes(*value)
return super()._arg_to_ctypes(*value)

if kind == 'charp' or kind == 'bytep':
def _to_string(self, maxlen):
Expand All @@ -581,7 +581,7 @@ def _get_own_repr(self):
if getattr(self, '_own', False):
return 'owning %d bytes' % (
ctypes.sizeof(self._as_ctype_ptr.contents),)
return super(CTypesPtr, self)._get_own_repr()
return super()._get_own_repr()
#
if (BItem is self.ffi._get_cached_btype(model.void_type) or
BItem is self.ffi._get_cached_btype(model.PrimitiveType('char'))):
Expand Down Expand Up @@ -677,7 +677,7 @@ def _to_string(self, maxlen):
def _get_own_repr(self):
if getattr(self, '_own', False):
return 'owning %d bytes' % (ctypes.sizeof(self._blob),)
return super(CTypesArray, self)._get_own_repr()
return super()._get_own_repr()

def _convert_to_address(self, BClass):
if BClass in (CTypesPtr, None) or BClass._automatic_casts:
Expand Down Expand Up @@ -917,7 +917,7 @@ def __repr__(self):
def _get_own_repr(self):
if getattr(self, '_own_callback', None) is not None:
return 'calling %r' % (self._own_callback,)
return super(CTypesFunctionPtr, self)._get_own_repr()
return super()._get_own_repr()

def __call__(self, *args):
if has_varargs:
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def rawaddressof(self, BTypePtr, cdata, offset=None):
return BTypePtr._from_ctypes(ptr)


class CTypesLibrary(object):
class CTypesLibrary:

def __init__(self, backend, cdll):
self.backend = backend
Expand Down
2 changes: 1 addition & 1 deletion src/cffi/cffi_opcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .error import VerificationError

class CffiOp(object):
class CffiOp:
def __init__(self, op, arg):
self.op = op
self.arg = arg
Expand Down
2 changes: 1 addition & 1 deletion src/cffi/cparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _common_type_names(csource):
return words_used


class Parser(object):
class Parser:

def __init__(self):
self._declarations = {}
Expand Down
7 changes: 3 additions & 4 deletions src/cffi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def qualify(quals, replace_with):
return replace_with


class BaseTypeByIdentity(object):
class BaseTypeByIdentity:
is_array_type = False
is_raw_function = False

Expand All @@ -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 Expand Up @@ -371,8 +371,7 @@ def enumfields(self, expand_anonymous_struct_union=True):
if (name == '' and isinstance(type, StructOrUnion)
and expand_anonymous_struct_union):
# nested anonymous struct/union
for result in type.enumfields():
yield result
yield from type.enumfields()
else:
yield (name, type, bitsize, quals)

Expand Down
2 changes: 1 addition & 1 deletion src/cffi/pkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call(libname, flag, encoding=sys.getfilesystemencoding()):
a.append(libname)
try:
pc = subprocess.Popen(a, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except EnvironmentError as e:
except OSError as e:
raise PkgConfigError("cannot run pkg-config: %s" % (str(e).strip(),))

bout, berr = pc.communicate()
Expand Down
10 changes: 3 additions & 7 deletions src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,6 @@ def _print_string_literal_in_array(self, s):
s = s.encode('utf-8') # -> bytes
else:
s.decode('utf-8') # got bytes, check for valid utf-8
try:
s.decode('ascii')
except UnicodeDecodeError:
s = b'# -*- encoding: utf8 -*-\n' + s
for line in s.splitlines(True):
comment = line
if type('//') is bytes: # python2
Expand Down Expand Up @@ -1401,7 +1397,7 @@ class NativeIO(io.BytesIO):
def write(self, s):
if isinstance(s, unicode):
s = s.encode('ascii')
super(NativeIO, self).write(s)
super().write(s)

def _is_file_like(maybefile):
# compare to xml.etree.ElementTree._get_writer
Expand All @@ -1423,11 +1419,11 @@ def _make_c_or_py_source(ffi, module_name, preamble, target_file, verbose):
try:
with open(target_file, 'r') as f1:
if f1.read(len(output) + 1) != output:
raise IOError
raise OSError
if verbose:
print("(already up-to-date)")
return False # already up-to-date
except IOError:
except OSError:
tmp_file = '%s.~%d' % (target_file, os.getpid())
with open(tmp_file, 'w') as f1:
f1.write(output)
Expand Down
Loading
Loading