Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
96b9e05
Fix #295
tristanlatr Jul 11, 2023
6550919
Fix the _ReferenceTransform for annotations.
tristanlatr Jul 11, 2023
34e2c54
Fix mypy
tristanlatr Jul 11, 2023
ef41a2f
fix pyflakes
tristanlatr Jul 11, 2023
bd8af40
fix ref
tristanlatr Jul 11, 2023
bd69087
Fix issue regarding builtin names. Introduce the rawtarget attribute …
tristanlatr Jul 12, 2023
0fd9982
Fix big loop issue
tristanlatr Jul 12, 2023
b84f24c
Better test coverage for the linker
tristanlatr Jul 12, 2023
31144e5
Introduce Class.parsed_bases, Function.parsed_decorators, Function.pa…
tristanlatr Jul 13, 2023
e39b771
Add tests
tristanlatr Jul 13, 2023
f0f694d
Fix mypy
tristanlatr Jul 13, 2023
dd2cf17
fix static checks
tristanlatr Jul 13, 2023
6221144
Merge branch 'master' into 280-295-rework-names-in-type-annotations
tristanlatr Jan 20, 2024
6626405
Merge branch 'master' into 280-295-rework-names-in-type-annotations
tristanlatr Apr 3, 2024
52d550b
Merge branch 'master' into 280-295-rework-names-in-type-annotations
tristanlatr Jan 30, 2025
a1a72a7
Stop warning about annotation, pydoctor is not a checker.
tristanlatr Feb 1, 2025
972993d
Create an actual Reference object
tristanlatr Feb 1, 2025
74e8154
Merge branch 'master' into 280-295-rework-names-in-type-annotations
tristanlatr Jul 19, 2025
1654b6d
Ensure the link not found warnings always show the text written in th…
tristanlatr Jul 19, 2025
066242c
Preprocess modules to gather meta variables before any docstring pars…
tristanlatr Jul 20, 2025
784d069
Add missing future import
tristanlatr Jul 20, 2025
9674845
Ensure hidden objects doesn't gets their docstring parsed.
tristanlatr Jul 20, 2025
792d278
wip testing
tristanlatr Jul 20, 2025
fa75e65
Add another unfinished test
tristanlatr Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions pydoctor/astbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def depart_Module(self, node: ast.Module) -> None:
self._tweak_constants_annotations(self.builder.current)
self._infer_attr_annotations(self.builder.current)
self.builder.pop(self.module)
epydoc2stan.transform_parsed_names(self.module)

def visit_ClassDef(self, node: ast.ClassDef) -> None:
# Ignore classes within functions.
Expand Down Expand Up @@ -1153,6 +1154,8 @@ def _get_all_ast_annotations() -> Iterator[Tuple[str, Optional[ast.expr]]]:
class ASTBuilder:
"""
Keeps tracks of the state of the AST build, creates documentable and adds objects to the system.

One ASTBuilder instance is only suitable to build one Module.
"""
ModuleVistor = ModuleVistor

Expand All @@ -1164,21 +1167,6 @@ def __init__(self, system: model.System):

self._stack: List[model.Documentable] = []


def parseFile(self, path: Path, ctx: model.Module) -> Optional[ast.Module]:
try:
return self.system._ast_parser.parseFile(path)
except Exception as e:
ctx.report(f"cannot parse file, {e}")
return None

def parseString(self, string:str, ctx: model.Module) -> Optional[ast.Module]:
try:
return self.system._ast_parser.parseString(string)
except Exception:
ctx.report("cannot parse string")
return None

def _push(self,
cls: Type[DocumentableT],
name: str,
Expand Down Expand Up @@ -1270,14 +1258,6 @@ def addAttribute(self,

def processModuleAST(self, mod_ast: ast.Module, mod: model.Module) -> None:

for name, node in findModuleLevelAssign(mod_ast):
try:
module_var_parser = MODULE_VARIABLES_META_PARSERS[name]
except KeyError:
continue
else:
module_var_parser(node, mod)

vis = self.ModuleVistor(self, mod)
vis.extensions.add(*self.system._astbuilder_visitors)
vis.extensions.attach_visitor(vis)
Expand All @@ -1304,7 +1284,7 @@ def exception(self) -> Exception:
def __init__(self) -> None:
self.ast_cache: Dict[Path, ast.Module | SyntaxTreeParser._Error] = {}

def parseFile(self, path: Path) -> ast.Module:
def parseFileOnly(self, path: Path) -> ast.Module:
try:
r = self.ast_cache[path]
except KeyError:
Expand All @@ -1322,14 +1302,28 @@ def parseFile(self, path: Path) -> ast.Module:
raise r.exception()
return r

def parseString(self, string:str) -> ast.Module:
def parseStringOnly(self, string:str) -> ast.Module:
mod = None
try:
mod = _parse(string)
except (SyntaxError, ValueError) as e:
raise SyntaxError("cannot parse string") from e
return mod

def parseFile(self, path: Path, ctx: model.Module) -> model.ParsedAstModule | None:
try:
return model.ParsedAstModule(self.parseFileOnly(path))
except Exception as e:
ctx.report(f"cannot parse file, {e}")
return None

def parseString(self, string:str, ctx: model.Module) -> model.ParsedAstModule | None:
try:
return model.ParsedAstModule(self.parseStringOnly(string))
except Exception:
ctx.report("cannot parse string")
return None

model.System.defaultBuilder = ASTBuilder
model.System.syntaxTreeParser = SyntaxTreeParser

Expand Down
6 changes: 4 additions & 2 deletions pydoctor/epydoc/markup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def link_to(self, target: str, label: "Flattenable", *, is_annotation: bool = Fa
@return: The link, or just the label if the target was not found.
"""

def link_xref(self, target: str, label: "Flattenable", lineno: int) -> Tag:
def link_xref(self, target: str, label: "Flattenable", lineno: int, rawtarget: str | None = None) -> Tag:
"""
Format a cross-reference link to a Python identifier.
This will resolve the identifier to any reasonable target,
Expand All @@ -326,8 +326,10 @@ def link_xref(self, target: str, label: "Flattenable", lineno: int) -> Tag:
@param label: The label to show for the link.
@param lineno: The line number within the docstring at which the
crossreference is located.
@param rawtarget: The name of the Python identifier that
should be linked to, as written in the docstring, for warning purposes.
If it's left None, the C{identifier} will be used instead.
@return: The link, or just the label if the target was not found.
In either case, the returned top-level tag will be C{<code>}.
"""

def switch_context(self, ob:Optional['Documentable']) -> ContextManager[None]:
Expand Down
Loading
Loading