Skip to content

Commit aeb44df

Browse files
committed
add docstrings
1 parent 8582e69 commit aeb44df

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
release-build:
12+
pypi-publish:
1313
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write
1416

1517
steps:
1618
- uses: actions/checkout@v4
@@ -21,29 +23,6 @@ jobs:
2123
run: |
2224
uv build
2325
24-
- name: Upload distributions
25-
uses: actions/upload-artifact@v4
26-
with:
27-
name: release-dists
28-
path: dist/
29-
30-
pypi-publish:
31-
runs-on: ubuntu-latest
32-
needs:
33-
- release-build
34-
permissions:
35-
id-token: write
36-
37-
environment:
38-
name: pypi
39-
url: https://pypi.org/p/runtime-docstrings
40-
41-
steps:
42-
- name: Retrieve release distributions
43-
uses: actions/download-artifact@v4
44-
with:
45-
name: release-dists
46-
path: dist/
47-
4826
- name: Publish release distributions to PyPI
49-
uses: pypa/gh-action-pypi-publish@release/v1
27+
run: |
28+
uv publish

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "runtime-docstrings"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Runtime access to Python class attribute docstrings (PEP 224)"
55
readme = "README.md"
66
authors = [{ name = "gesslerpd", email = "[email protected]" }]

src/runtime_docstrings/_parser.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import ast
1010
import types
1111
from enum import Enum
12-
from typing import TypeVar
13-
14-
T = TypeVar("T", bound=type)
1512

1613

1714
def _parse_docstrings(node: ast.ClassDef) -> dict[str, str]:
@@ -35,6 +32,15 @@ def _parse_docstrings(node: ast.ClassDef) -> dict[str, str]:
3532

3633

3734
def get_docstrings(cls: type) -> dict[str, str]:
35+
"""Parse and return a mapping of attribute names to their docstrings for a given class.
36+
37+
Args:
38+
cls: The class to parse attribute docstrings from.
39+
40+
Returns:
41+
A dictionary where keys are attribute names and values are their
42+
corresponding docstrings.
43+
"""
3844
if "__attribute_docs__" in cls.__dict__:
3945
return cls.__attribute_docs__
4046
source = dedent(inspect.getsource(cls))
@@ -76,7 +82,18 @@ def _attach_enum(cls: type[Enum], comments: dict[str, str]) -> None:
7682
member.__doc__ = comments[name]
7783

7884

79-
def docstrings(cls: T) -> T:
85+
def docstrings(cls: type) -> type:
86+
"""Decorator that attaches attribute/member docstrings to a class.
87+
88+
If the class is an enum, docstrings are attached via enum members.
89+
90+
If the class is a dataclass, docstrings are attached via field metadata.
91+
92+
Parameters:
93+
cls: The class to process.
94+
Returns:
95+
The same class with attached docstrings.
96+
"""
8097
assert inspect.isclass(cls), "cls must be a class"
8198

8299
# Extract docstrings from the class definition

0 commit comments

Comments
 (0)