Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Patch bundled simplegeneric for Python 3 compatibility.

  • Loading branch information...
commit d82fb264119c52b2747b563b899279cf6ea843a9 1 parent bcd1047
Thomas Kluyver authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 IPython/external/simplegeneric/_simplegeneric.py
18 IPython/external/simplegeneric/_simplegeneric.py
View
@@ -1,5 +1,6 @@
"""This is version 0.7 of Philip J. Eby's simplegeneric module
-(http://pypi.python.org/pypi/simplegeneric)
+(http://pypi.python.org/pypi/simplegeneric), patched to work with Python 3,
+which doesn't support old-style classes.
"""
#Name: simplegeneric
@@ -12,8 +13,12 @@
__all__ = ["generic"]
-from types import ClassType, InstanceType
-classtypes = type, ClassType
+try:
+ from types import ClassType, InstanceType
+except ImportError:
+ classtypes = type
+else:
+ classtypes = type, ClassType
def generic(func):
"""Create a simple generic function"""
@@ -29,7 +34,12 @@ def _by_class(*args, **kw):
else:
return func(*args, **kw)
- _by_type = {object: func, InstanceType: _by_class}
+ _by_type = {object: func}
+ try:
+ _by_type[InstanceType] = _by_class
+ except NameError: # Python 3
+ pass
+
_gbt = _by_type.get
def when_type(*types):
Please sign in to comment.
Something went wrong with that request. Please try again.