X Tutup
Skip to content

Commit c919c96

Browse files
committed
Fix inspection.is_callable().
1 parent a2d2a95 commit c919c96

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

bpython/inspection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
try:
3636
collections.Callable
3737
has_collections_callable = True
38-
try:
39-
import types
40-
types.InstanceType
41-
has_instance_type = True
42-
except AttributeError:
43-
has_instance_type = False
4438
except AttributeError:
4539
has_collections_callable = False
40+
try:
41+
import types
42+
types.InstanceType
43+
has_instance_type = True
44+
except AttributeError:
45+
has_instance_type = False
4646

4747
py3 = sys.version_info[0] == 3
4848

bpython/test/test_inspection.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
from bpython import inspection
4+
5+
class TestInspection(unittest.TestCase):
6+
def test_is_callable(self):
7+
class OldCallable:
8+
def __call__(self):
9+
pass
10+
11+
class Callable(object):
12+
def __call__(self):
13+
pass
14+
15+
class OldNoncallable:
16+
pass
17+
18+
class Noncallable(object):
19+
pass
20+
21+
def spam():
22+
pass
23+
24+
self.assertTrue(inspection.is_callable(spam))
25+
self.assertTrue(inspection.is_callable(Callable))
26+
self.assertTrue(inspection.is_callable(Callable()))
27+
self.assertTrue(inspection.is_callable(OldCallable))
28+
self.assertTrue(inspection.is_callable(OldCallable()))
29+
self.assertFalse(inspection.is_callable(Noncallable()))
30+
self.assertFalse(inspection.is_callable(OldNoncallable()))
31+
self.assertFalse(inspection.is_callable(None))

0 commit comments

Comments
 (0)
X Tutup