Show More
@@ -48,8 +48,7 b' def dir2(obj):' | |||
|
48 | 48 | """dir2(obj) -> list of strings |
|
49 | 49 | |
|
50 | 50 | Extended version of the Python builtin dir(), which does a few extra |
|
51 |
checks, and |
|
|
52 | dir(), such as Traits and PyCrust. | |
|
51 | checks, and handles Traits objects, which can confuse dir(). | |
|
53 | 52 | |
|
54 | 53 | This version is guaranteed to return only a list of true strings, whereas |
|
55 | 54 | dir() returns anything that objects inject into themselves, even if they |
@@ -72,15 +71,13 b' def dir2(obj):' | |||
|
72 | 71 | |
|
73 | 72 | |
|
74 | 73 | # for objects with Enthought's traits, add trait_names() list |
|
75 | # for PyCrust-style, add _getAttributeNames() magic method list | |
|
76 | for attr in ('trait_names', '_getAttributeNames'): | |
|
77 | try: | |
|
78 | func = getattr(obj, attr) | |
|
79 | if callable(func): | |
|
80 | words |= set(func()) | |
|
81 |
|
|
|
82 | # TypeError: obj is class not instance | |
|
83 | pass | |
|
74 | try: | |
|
75 | func = getattr(obj, 'trait_names') | |
|
76 | if callable(func): | |
|
77 | words |= set(func()) | |
|
78 | except: | |
|
79 | # TypeError: obj is class not instance | |
|
80 | pass | |
|
84 | 81 | |
|
85 | 82 | # filter out non-string attributes which may be stuffed by dir() calls |
|
86 | 83 | # and poor coding in third-party modules |
General Comments 0
You need to be logged in to leave comments.
Login now