Commit a072caf
committed
gp-opengraph(refactor[imports]): use namespace imports for stdlib modules
why: PR #22 code review flagged three ``from <stdlib> import <name>``
import statements that violate CLAUDE.md line 457:
Use namespace imports for standard library modules:
`import enum` instead of `from enum import Enum`
Exception: `dataclasses` module may use
`from dataclasses import dataclass, field` for cleaner
decorator syntax
Every existing workspace package follows this — e.g. gp-sphinx's own
config.py uses ``import pathlib`` / ``import tomllib`` then
``pathlib.Path(...)`` / ``tomllib.loads(...)``.
what:
- packages/gp-opengraph/src/gp_opengraph/__init__.py:
* ``from types import NoneType`` -> ``import types`` +
``types.NoneType`` at each call site (four occurrences inside
``frozenset({...})`` literals for add_config_value).
* ``from urllib.parse import urljoin, urlparse, urlsplit, urlunsplit``
-> ``import urllib.parse`` with each call qualified:
``urllib.parse.urljoin(...)``, ``urllib.parse.urlparse(...)``,
``urllib.parse.urlsplit(...)``, ``urllib.parse.urlunsplit(...)``.
- packages/gp-opengraph/src/gp_opengraph/_title.py:
* ``from html.parser import HTMLParser`` -> ``import html.parser``;
subclass declaration becomes ``class HTMLTextParser(html.parser.HTMLParser)``.
- packages/gp-opengraph/src/gp_opengraph/_meta.py:
* Same HTMLParser rewrite as _title.py.
Left as-is (already compliant):
- ``from xml.etree import ElementTree`` in gp_sitemap — this imports a
*submodule*, not a name, and is the canonical idiom (equivalent to
``import xml.etree.ElementTree as ElementTree``). CLAUDE.md's
example targets ``from enum import Enum`` (name import), not
submodule aliasing.
- ``from collections.abc import Set`` / ``Iterable`` inside
``TYPE_CHECKING`` blocks — gp_sphinx itself does this at
config.py#L17, so the convention allows type-only imports this way.
No behavior change; purely an import refactor.
CI gate (all green before commit):
- uv run ruff check . --fix --show-fixes: clean
- uv run ruff format .: no changes
- uv run mypy: Success (176 source files)
- uv run py.test --reruns 0 -vvv: 1199 passed, 3 skipped
- just build-docs: build succeeded1 parent 3742a34 commit a072caf
3 files changed
Lines changed: 17 additions & 15 deletions
Lines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | | - | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
209 | 211 | | |
210 | 212 | | |
211 | 213 | | |
| |||
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
303 | | - | |
| 305 | + | |
304 | 306 | | |
305 | 307 | | |
306 | 308 | | |
307 | 309 | | |
308 | 310 | | |
309 | | - | |
| 311 | + | |
310 | 312 | | |
311 | 313 | | |
312 | 314 | | |
| |||
319 | 321 | | |
320 | 322 | | |
321 | 323 | | |
322 | | - | |
| 324 | + | |
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
328 | 330 | | |
329 | | - | |
| 331 | + | |
330 | 332 | | |
331 | 333 | | |
332 | 334 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments