Skip to content

sections: import the styles at the top level - #195

Merged
rr- merged 4 commits into
mainfrom
rework/60-top-level-imports
Nov 7, 2026
Merged

rr- merged 4 commits into
mainfrom
rework/60-top-level-imports

Conversation

@rr-

@rr- rr- commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Move every import on main to the top level of its module, so that git grep -nE '^\s+(import |from \S+ import )' -- '*.py' finds only the example inside the docstring_parser.sections docstring.

  • sections.default_sections imported the four style modules inside the function, because every style imports SectionSpec and the rest from sections. The shared pieces (Layout, SectionSpec, ParserCache, apply) move down to a private docstring_parser._sections, which the styles and parser import. The public docstring_parser.sections keeps its docstring, its __all__ and default_sections, and imports the styles at the top level. Its public names are unchanged.
  • test_from_module_attribute_docstrings imported its own module inside the test. It now takes it from sys.modules[__name__].
  • tests/_pydoctor.py is deleted rather than changed. Its try: from pydoctor.model import ... guarded an optional dependency, and nothing has loaded the file since Update CI #93: the API docs hide docstring_parser.tests with --privacy instead of --system-class.
  • PLC0415 needs no config change. The PL selection already enables it in the ruff that just lint runs (v0.17.3 via prek). Only the noqa comments silenced it before, and they are gone. I checked that a nested import makes lint fail.
  • No CHANGELOG line, since nothing users can see changes.
  • Gates: just test passes (6612), just lint passes, just update-cases changes nothing, and parity against origin/main shows no differences. Bench against origin/main: max 1.04 on 3.14 and 1.02 on 3.8.

rr- added 3 commits November 7, 2026 12:45
default_sections imported the style modules inside the function, as
every style imports SectionSpec and the rest from sections. Move those
shared pieces down to a private _sections module that the styles
import, so the public sections module can import the styles at the top
level. Its public names stay the same.
The module attribute test imported its own module inside the test to
parse it. Take it from sys.modules instead.
The API docs hide docstring_parser.tests with --privacy since #93, so
nothing loads HidesTestsPydoctorSystem any more. Its optional import of
pydoctor was the last import not at the top level.
@rr- rr- self-assigned this Nov 7, 2026
@rr-
rr- merged commit ed166fb into main Nov 7, 2026
26 checks passed
@rr-
rr- deleted the rework/60-top-level-imports branch November 7, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant