Apply a function on publicly exposed API components. Recursively iterates over the members of the passed object. It omits any '_' prefixed and thirdparty (non pyarrow) symbols. Parameters ---------- fn : callable A function to apply on all traver
(self, fn, obj, from_package)
| 102 | self.symbols = set(symbols or {'pyarrow'}) |
| 103 | |
| 104 | def traverse(self, fn, obj, from_package): |
| 105 | """Apply a function on publicly exposed API components. |
| 106 | |
| 107 | Recursively iterates over the members of the passed object. It omits |
| 108 | any '_' prefixed and thirdparty (non pyarrow) symbols. |
| 109 | |
| 110 | Parameters |
| 111 | ---------- |
| 112 | fn : callable |
| 113 | A function to apply on all traversed objects. |
| 114 | obj : Any |
| 115 | The object to start from. |
| 116 | from_package : string |
| 117 | Predicate to only consider objects from this package. |
| 118 | """ |
| 119 | todo = [obj] |
| 120 | seen = set() |
| 121 | |
| 122 | while todo: |
| 123 | obj = todo.pop() |
| 124 | if obj in seen: |
| 125 | continue |
| 126 | else: |
| 127 | seen.add(obj) |
| 128 | |
| 129 | fn(obj) |
| 130 | |
| 131 | for name in dir(obj): |
| 132 | if name.startswith('_'): |
| 133 | continue |
| 134 | |
| 135 | member = getattr(obj, name) |
| 136 | module = _get_module(member) |
| 137 | if module is None or not module.startswith(from_package): |
| 138 | continue |
| 139 | # Is it a Cython-generated method? If so, try to detect |
| 140 | # whether it only has a implicitly-generated docstring, |
| 141 | # and no user-defined docstring following it. |
| 142 | # The generated docstring would lack description of method |
| 143 | # parameters and therefore fail Numpydoc validation. |
| 144 | if hasattr(member, '__objclass__'): |
| 145 | doc = getattr(member, '__doc__', None) |
| 146 | # The Cython-generated docstring would be a one-liner, |
| 147 | # such as "ReadOptions.equals(self, ReadOptions other)". |
| 148 | if (doc and '\n' not in doc and f'.{name}(' in doc): |
| 149 | continue |
| 150 | todo.append(member) |
| 151 | |
| 152 | @contextmanager |
| 153 | def _apply_patches(self): |
no test coverage detected