[pypy-commit] cffi default: fix handling w/ py3 hasattr, which only swallows AttributeErrors
pjenvey
noreply at buildbot.pypy.org
Sat Apr 6 12:37:00 CEST 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r1241:e2b9db908b90
Date: 2013-04-05 12:01 -0700
http://bitbucket.org/cffi/cffi/changeset/e2b9db908b90/
Log: fix handling w/ py3 hasattr, which only swallows AttributeErrors
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -370,7 +370,10 @@
if key in ffi._parser._declarations:
tp = ffi._parser._declarations[key]
BType = ffi._get_cached_btype(tp)
- value = backendlib.load_function(BType, name)
+ try:
+ value = backendlib.load_function(BType, name)
+ except KeyError:
+ raise AttributeError(name)
library.__dict__[name] = value
return
#
diff --git a/testing/test_function.py b/testing/test_function.py
--- a/testing/test_function.py
+++ b/testing/test_function.py
@@ -345,3 +345,11 @@
assert lib.DD == 6
assert lib.EE == -5
assert lib.FF == -4
+
+ def test_missing_function(self):
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ int nonexistent();
+ """)
+ m = ffi.dlopen("m")
+ assert not hasattr(m, 'nonexistent')
More information about the pypy-commit
mailing list