twisted / pydoctor

This is pydoctor, an API documentation generator that works by static analysis.
https://pydoctor.readthedocs.io
Other
179 stars 48 forks source link

Rework reparenting #737

Closed tristanlatr closed 9 months ago

tristanlatr commented 9 months ago

Rework reparenting in post-processing. It ensures that for all time of visiting the ASTs, the model represent the real code structure, since no reparenting is done before post processing.

This patch changes some of the core pydoctor logic, so it should be carefully reviewed.

This changes will help fixing https://github.com/twisted/pydoctor/issues/295 as well as improve our capacity to fix https://github.com/twisted/pydoctor/issues/184 and other all related problems. Together with https://github.com/twisted/pydoctor/pull/723 it will finally fix https://github.com/twisted/pydoctor/issues/295.

Introduces the Module.imports attribute holding a list of resolved imports (like ast.alias but with full module names), this is required by the re-exporting process since only imported names should be reparented.

Introduces the System.modules attribute that is a dict from the module full names to the Module instances. This dict is not changed during reparenting. It's populated when the modules are added to the system. This behaviour better matches the python import system and makes us differentiate a module vs an object with the same fullname as the module in the parent package __init__.py for instance.

This PR should not introduce any changes in behaviour, except it fixes a bug in reparenting process when there as duplicates (see new tests).

codecov[bot] commented 9 months ago

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (1a7d052) 91.98% compared to head (416d1d0) 92.77%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #737 +/- ## ========================================== + Coverage 91.98% 92.77% +0.78% ========================================== Files 47 47 Lines 8147 8245 +98 Branches 1780 1976 +196 ========================================== + Hits 7494 7649 +155 + Misses 380 340 -40 + Partials 273 256 -17 ``` | [Files](https://app.codecov.io/gh/twisted/pydoctor/pull/737?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=twisted) | Coverage Δ | | |---|---|---| | [pydoctor/model.py](https://app.codecov.io/gh/twisted/pydoctor/pull/737?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=twisted#diff-cHlkb2N0b3IvbW9kZWwucHk=) | `94.88% <100.00%> (+1.90%)` | :arrow_up: | | [pydoctor/astbuilder.py](https://app.codecov.io/gh/twisted/pydoctor/pull/737?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=twisted#diff-cHlkb2N0b3IvYXN0YnVpbGRlci5weQ==) | `96.82% <91.95%> (+1.63%)` | :arrow_up: | ... and [23 files with indirect coverage changes](https://app.codecov.io/gh/twisted/pydoctor/pull/737/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=twisted)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tristanlatr commented 9 months ago

I'll close this PR since it makes more sens to merge an actual fix that builds on top of this PR.