Skip to content

Improve NamedDist docstring with fields documentation#1370

Merged
penelopeysm merged 2 commits into
TuringLang:mainfrom
ArpanC6:fix/nameddist-docstring
Apr 26, 2026
Merged

Improve NamedDist docstring with fields documentation#1370
penelopeysm merged 2 commits into
TuringLang:mainfrom
ArpanC6:fix/nameddist-docstring

Conversation

@ArpanC6
Copy link
Copy Markdown
Contributor

@ArpanC6 ArpanC6 commented Apr 26, 2026

What does this PR do?

The NamedDist struct previously had a very brief one line description which lacked detailed documentation.

Changes made

  1. Added a full struct signature to the docstring header.

  2. Included a # Fields section to explain the dist and name fields.

  3. Updated the documentation style to match the standard Julia documentation format used across the rest of the codebase.

Why?

Providing proper documentation for the fields helps both users and developers understand the purpose of the struct without needing to dive into the source code itself.

@ArpanC6
Copy link
Copy Markdown
Contributor Author

ArpanC6 commented Apr 26, 2026

@penelopeysm This is my first contribution to DynamicPPL.jl.
Please let me know if any changes are needed.

Copy link
Copy Markdown
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I recognise this is quite a small PR and it might seem nitpicky of me, but I'd still like to point out a couple of things to perhaps improve it further. None of these are intended as criticisms at all.

Comment thread src/distribution_wrappers.jl Outdated
using FillArrays: Fill

"""
NamedDist{variate, support, Td, Tv}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is totally correct -- however, because it is a description of the type, it doesn't tell people how to construct one of them. I personally like docs when they tell me about the constructors themselves (and I find that the type itself is not that important -- you only need it if you are writing a function that dispatches on the type, which is much less likely for the average user user).

Suggested change
NamedDist{variate, support, Td, Tv}
NamedDist(dist::Distribution, name::Symbol)

Comment on lines +17 to 26
# Fields

- `dist::Td`: The underlying distribution.
- `name::Tv`: The name of the random variable as a `VarName`.
"""
struct NamedDist{variate,support,Td<:Distribution{variate,support},Tv<:VarName} <:
Distribution{variate,support}
dist::Td
name::Tv
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually add strings on top of the fields themselves, and then use $(TYPEDFIELDS) in the docstring which will automatically pull in the comments. (The TYPEDFIELDS identifier is provided by DocStringExtensions.jl: https://docstringextensions.juliadocs.org/latest/)

This helps ensure that the docstring stays in sync with the source code. For an example of this you can see e.g. LogPriorAccumulator in src/accumulators/default.jl (or equivalently grep for TYPEDFIELDS in the repo, there are several other examples).

@ArpanC6
Copy link
Copy Markdown
Contributor Author

ArpanC6 commented Apr 26, 2026

@penelopeysm Thank you for the feedback. I have updated the docstring to use the constructor signature and $(TYPEDFIELDS) as suggested.

Copy link
Copy Markdown
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@penelopeysm penelopeysm merged commit e7e9855 into TuringLang:main Apr 26, 2026
@ArpanC6
Copy link
Copy Markdown
Contributor Author

ArpanC6 commented Apr 26, 2026

Thank you!

Thank you for the review and for merging. Looking forward to contributing more.

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.

2 participants