Repository navigation
bug: Doc in module attributes are not picked up #12
Description
Activity
- addedunconfirmedThis bug was not reproduced yetThis bug was not reproduced yet
on Feb 5, 2025 Hey @willemkokke, thanks a lot for the report! I was able to confirm. I also added the relevant code to the issue body, to be sure not to lose it if you ever delete the repro repository 🙂
So, yeah, that's surprising! I'll investigate asap 😄
- addedbugSomething isn't workingSomething isn't workingand removedunconfirmedThis bug was not reproduced yetThis bug was not reproduced yet
on Feb 5, 2025 Ah, right, griffe-typingdoc only finds
Docannotations in, well, type annotations (after:), not in values. I'd say this would be part of a larger feature (which was explicitly rejected in the PEP I think) where docstrings attached to type are reused in other objects that reference/use these types.ChecksumString = Annotated[ str, Doc("A sha256 checksum."), StringConstraints(pattern="^[a-fA-F0-9]{64}$") ] def check(checksum: ChecksumString) -> None: """Hey. Parameters section added, checksum param has doc from ChecksumString type."""
I think it's too bad this idea is rejected by the way, would have used it myself 😄 Anyway griffe-typingdoc is already taking a few liberties so we could still consider implementing this feature.
- addedfeatureNew feature or requestNew feature or requestfundIssue priority can be boostedIssue priority can be boostedand removedbugSomething isn't workingSomething isn't working
on Feb 5, 2025 Oh dear.. Just after posting this I found https://gist.github.com/pawamoy/a12cb4a5f66d913519070b52b2a9d54b, and I realise the syntax should be
ChecksumString: Annotated[ str, Doc("A sha256 checksum."), StringConstraints(pattern="^[a-fA-F0-9]{64}$") ]
instead of
ChecksumString = Annotated[ str, Doc("A sha256 checksum."), StringConstraints(pattern="^[a-fA-F0-9]{64}$") ]
I think what I actually did when assigning was creating an implicit TypeAlias, not a .... Yeah what you said ;)
Hmm, I do actually want to create a TypeAlias in this case, because I want a reusable string type that can only hold checksums in a Pydantic model. Ah well that is enough yak shaving, good old fashioned docstrings will do the job in this case.
Sorry for the noise!
Sorry, didn't mean to close :-(
Reacted by Timothée MazzucotelliNo worries! Keeping open as this is a cool feature 🙂 I think you can do this though:
ChecksumString: Annotated[TypeAlias, Doc("A sha256 checksum.")] = Annotated[str, StringConstraints(pattern="^[a-fA-F0-9]{64}$")]
Pylance is dumb then /s 🤡
You're welcome!

Description of the bug
griffe-typingdoc seems to not work on module attributes.
To Reproduce
Expected behavior
The generated docs should have a description for ChecksumString and NormalString.
Environment information
griffe-typingdocv0.2.7Additional context
Only learned about pep 727 yesterday when fine-tuning my mkdocstrings configuration. I might be misunderstanding it completely!
I've also tried this with
unwrap_annotated: falsewith identical results.Urgency is low, the alternative of just using a docstring after the module attribute works fine.