Show More
@@ -1,5 +1,6 b'' | |||||
1 | """This is version 0.7 of Philip J. Eby's simplegeneric module |
|
1 | """This is version 0.7 of Philip J. Eby's simplegeneric module | |
2 | (http://pypi.python.org/pypi/simplegeneric) |
|
2 | (http://pypi.python.org/pypi/simplegeneric), patched to work with Python 3, | |
|
3 | which doesn't support old-style classes. | |||
3 | """ |
|
4 | """ | |
4 |
|
5 | |||
5 | #Name: simplegeneric |
|
6 | #Name: simplegeneric | |
@@ -12,8 +13,12 b'' | |||||
12 |
|
13 | |||
13 | __all__ = ["generic"] |
|
14 | __all__ = ["generic"] | |
14 |
|
15 | |||
15 | from types import ClassType, InstanceType |
|
16 | try: | |
16 | classtypes = type, ClassType |
|
17 | from types import ClassType, InstanceType | |
|
18 | except ImportError: | |||
|
19 | classtypes = type | |||
|
20 | else: | |||
|
21 | classtypes = type, ClassType | |||
17 |
|
22 | |||
18 | def generic(func): |
|
23 | def generic(func): | |
19 | """Create a simple generic function""" |
|
24 | """Create a simple generic function""" | |
@@ -29,7 +34,12 b' def generic(func):' | |||||
29 | else: |
|
34 | else: | |
30 | return func(*args, **kw) |
|
35 | return func(*args, **kw) | |
31 |
|
36 | |||
32 |
_by_type = {object: func |
|
37 | _by_type = {object: func} | |
|
38 | try: | |||
|
39 | _by_type[InstanceType] = _by_class | |||
|
40 | except NameError: # Python 3 | |||
|
41 | pass | |||
|
42 | ||||
33 | _gbt = _by_type.get |
|
43 | _gbt = _by_type.get | |
34 |
|
44 | |||
35 | def when_type(*types): |
|
45 | def when_type(*types): |
General Comments 0
You need to be logged in to leave comments.
Login now