Coverage for src/griffe_public_redundant_aliases/_internal/extension.py: 94.12%
11 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 17:33 +0200
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 17:33 +0200
1from __future__ import annotations
3import ast
4from typing import Any
6import griffe
9class PublicRedundantAliasesExtension(griffe.Extension):
10 """Mark objects imported with redundant aliases as public."""
12 def on_alias_instance(self, *, node: ast.AST | griffe.ObjectNode, alias: griffe.Alias, **kwargs: Any) -> None: # noqa: ARG002
13 """Mark alias as public if it corresponds to an import with a redundant alias."""
14 # Only static analysis and import nodes are supported.
15 if isinstance(node, ast.AST) and isinstance(node, (ast.Import, ast.ImportFrom)): 15 ↛ exitline 15 didn't return from function 'on_alias_instance' because the condition on line 15 was always true
16 # Search import corresponding to alias.
17 for name in node.names:
18 if name.name == alias.name and name.name == name.asname:
19 # Found import corresponding to alias,
20 # and import uses a redundant alias.
21 alias.public = True
22 return