Skip to content

Commit

Permalink
Fix undefined names in Python code
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jul 25, 2024
1 parent 9e03127 commit 16569e9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions demo/_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

from _curses_cffi import ffi, lib

try:
unicode
except NameError:
unicode = str


def _copy_to_globals(name):
globals()[name] = getattr(lib, name)
Expand Down
1 change: 1 addition & 0 deletions demo/bsdopendirtype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from _bsdopendirtype import ffi, lib


Expand Down
1 change: 1 addition & 0 deletions demo/recopendirtype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from _recopendirtype import ffi, lib


Expand Down
2 changes: 1 addition & 1 deletion src/cffi/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _extension_suffixes():
else:
class NativeIO(io.BytesIO):
def write(self, s):
if isinstance(s, unicode):
if isinstance(s, unicode): # noqa: F821
s = s.encode('ascii')
super(NativeIO, self).write(s)

Expand Down
2 changes: 1 addition & 1 deletion testing/cffi0/test_zdistutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def make_ffi(**verifier_args):
prev_compile = ffiplatform.compile
try:
if targetpackage == ext_package:
ffiplatform.compile = lambda *args: dont_call_me_any_more
ffiplatform.compile = lambda *args: dont_call_me_any_more # noqa: F821
# won't find it in tmpdir, but should find it correctly
# installed in udir
ffi, lib = make_ffi()
Expand Down
9 changes: 5 additions & 4 deletions testing/cffi1/test_recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def test_include_8():

def test_unicode_libraries():
try:
unicode
unicode # noqa: F821
except NameError:
pytest.skip("for python 2.x")
#
Expand All @@ -757,9 +757,10 @@ def test_unicode_libraries():
if distutils.ccompiler.get_default_compiler() == 'msvc':
lib_m = 'msvcrt'
ffi = FFI()
ffi.cdef(unicode("float sin(double); double cos(double);"))
lib = verify(ffi, 'test_math_sin_unicode', unicode('#include <math.h>'),
libraries=[unicode(lib_m)], ignore_warnings=True)
ffi.cdef(unicode("float sin(double); double cos(double);")) # noqa: F821
lib = verify(ffi, 'test_math_sin_unicode',
unicode('#include <math.h>'), # noqa: F821
libraries=[unicode(lib_m)], ignore_warnings=True) # noqa: F821
assert lib.cos(1.43) == math.cos(1.43)

def test_incomplete_struct_as_arg():
Expand Down
2 changes: 1 addition & 1 deletion testing/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __add__(self, other):
return eval('u'+repr(other).replace(r'\\u', r'\u')
.replace(r'\\U', r'\U'))
u = U()
long = long # for further "from testing.support import long"
long = long # noqa: F821 for further "from testing.support import long"
assert u+'a\x00b' == eval(r"u'a\x00b'")
assert u+'a\u1234b' == eval(r"u'a\u1234b'")
assert u+'a\U00012345b' == eval(r"u'a\U00012345b'")
Expand Down

0 comments on commit 16569e9

Please sign in to comment.