Esempio n. 1
0
    def _is_private(self, path, name, obj):
        """Returns whether a name is private or not."""

        # Skip objects blocked by doc_controls.
        if doc_controls.should_skip(obj):
            return True

        if doc_controls.should_doc_private(obj):
            return False

        if inspect.ismodule(obj):
            mod_base_dirs = get_module_base_dirs(obj)
            # This check only handles normal packages/modules. Namespace-package
            # contents will get filtered when the submodules are checked.
            if len(mod_base_dirs) == 1:
                mod_base_dir = mod_base_dirs[0]
                # Check that module is in one of the `self._base_dir`s
                if not any(base in mod_base_dir.parents
                           for base in self._base_dir):
                    return True

        # Skip objects blocked by the private_map
        if name in self._private_map.get('.'.join(path), []):
            return True

        # Skip "_" hidden attributes
        if name.startswith('_') and name not in ALLOWED_DUNDER_METHODS:
            return True

        return False
Esempio n. 2
0
    def _is_private(self, path, name, obj):
        """Returns whether a name is private or not."""

        # Skip objects blocked by doc_controls.
        if doc_controls.should_skip(obj):
            return True

        if doc_controls.should_doc_private(obj):
            return False

        # Skip modules outside of the package root.
        if inspect.ismodule(obj):
            if hasattr(obj, '__file__'):
                # `startswith` will match any item in a tuple if a tuple of base_dir
                # are passed.
                # It's important that this is a string comparison not a `relpath`,
                # because in some cases `base_dir` may not a directory but a single
                # file path.
                if not obj.__file__.startswith(self._base_dir):
                    return True

        # Skip objects blocked by the private_map
        if name in self._private_map.get('.'.join(path), []):
            return True

        # Skip "_" hidden attributes
        if name.startswith('_') and name not in ALLOWED_DUNDER_METHODS:
            return True

        return False
Esempio n. 3
0
def filter_private_symbols(path: Sequence[str], parent: Any,
                           children: Children) -> Children:
    del path
    del parent
    for name, child in children:
        # Skip "_" hidden attributes
        if name.startswith('_') and name not in ALLOWED_DUNDER_METHODS:
            if not doc_controls.should_doc_private(child):
                continue
        yield (name, child)