|
9 | 9 | from . import class_declaration_traits
|
10 | 10 | from . import class_traits
|
11 | 11 | from . import traits_impl_details
|
| 12 | +from . import runtime_errors |
12 | 13 |
|
13 | 14 |
|
14 | 15 | class internal_type_traits(object):
|
@@ -72,7 +73,10 @@ def value_type(type_):
|
72 | 73 | 'Type "%s" is not an instantiation of \
|
73 | 74 | boost::shared_ptr or std::shared_ptr' %
|
74 | 75 | type_.decl_string)
|
75 |
| - return internal_type_traits.get_by_name(type_, "element_type") |
| 76 | + try: |
| 77 | + return internal_type_traits.get_by_name(type_, "element_type") |
| 78 | + except runtime_errors.declaration_not_found_t: |
| 79 | + return _search_in_bases(type_) |
76 | 80 |
|
77 | 81 |
|
78 | 82 | class auto_ptr_traits(object):
|
@@ -103,4 +107,23 @@ def value_type(type_):
|
103 | 107 | raise TypeError(
|
104 | 108 | 'Type "%s" is not instantiation of std::auto_ptr' %
|
105 | 109 | type_.decl_string)
|
106 |
| - return internal_type_traits.get_by_name(type_, "element_type") |
| 110 | + try: |
| 111 | + return internal_type_traits.get_by_name(type_, "element_type") |
| 112 | + except runtime_errors.declaration_not_found_t: |
| 113 | + return _search_in_bases(type_) |
| 114 | + |
| 115 | + |
| 116 | +def _search_in_bases(type_): |
| 117 | + """Implementation detail.""" |
| 118 | + found = False |
| 119 | + for base_type in type_.declaration.bases: |
| 120 | + try: |
| 121 | + found = internal_type_traits.get_by_name( |
| 122 | + base_type.related_class, "element_type") |
| 123 | + except runtime_errors.declaration_not_found_t: |
| 124 | + pass |
| 125 | + if found: |
| 126 | + return found |
| 127 | + raise RuntimeError( |
| 128 | + ("Unable to find 'element_type' declaration '%s'" |
| 129 | + "in type '%s'.") % type_.decl_string) |
0 commit comments