Skip to content

Commit 92dccc9

Browse files
Python 2.6 compatibilty for isclass
1 parent 2a65a47 commit 92dccc9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

bpython/simpleeval.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
"""
3030

3131
import ast
32-
from six import string_types
3332
import inspect
33+
from six import string_types
3434
from six.moves import builtins
35+
import sys
36+
import types
3537

3638
from bpython import line as line_properties
3739
from bpython._py3compat import py3
@@ -47,6 +49,14 @@
4749
_name_type_nodes = (ast.Name,)
4850

4951

52+
# inspect.isclass is broken in Python 2.6
53+
if sys.version_info[:2] == (2, 6):
54+
def isclass(obj):
55+
return isinstance(obj, (type, types.ClassType))
56+
else:
57+
isclass = inspect.isclass
58+
59+
5060
class EvaluationError(Exception):
5161
"""Raised if an exception occurred in safe_eval."""
5262

@@ -267,7 +277,7 @@ def safe_get_attribute_new_style(obj, attr):
267277
if not is_new_style(obj):
268278
raise ValueError("%r is not a new-style class or object" % obj)
269279
to_look_through = (obj.__mro__
270-
if inspect.isclass(obj)
280+
if isclass(obj)
271281
else (obj,) + type(obj).__mro__)
272282

273283
for cls in to_look_through:

0 commit comments

Comments
 (0)