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