You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RUF067 allow docstrings in __init__.py in strict mode #27416
A convention in a codebase I work in is to prohibit all code in __init__.py files, including imports, setting __all__, etc. So RUF067 in strict mode is almost perfect for what I want. The only issue is that is also prohibits docstrings.
The reason we allow docstrings in __init__.py files is because it's the obvious (and maybe canonical?) place for module-level documentation. All of the alternatives (a separate README.md file, or its own python file or something) seem worse.
I may be lacking creativity, but allowing docstrings seems like the intuitive and commonly useful behavior, so I propose to change it to allow them.
Alternatively, if actually empty files is a popular use case, or just to preserve backwards compatibility, maybe it could be split out into a separate setting (--semi-strictly-empty-init-modules = true? 😉), or even separate rules.
For reference, the original issue and PR for this rule. The PR description notes:
I'm not really sure we need to flag docstrings even when the strict setting is enabled, but I just followed upstream for now.
I'm not opposed to it, as I guess I said on the PR 😄 I think some people really do prefer totally empty __init__.py files, though, so some kind of three-state config option might be needed, as you said. But I'm curious what others think.
@ntBre do you remember if this is something we discussed when we added the rule? I tried to find some additional context on why the upstream rule denied docstrings but it seems to have been this way since the beginning.
I am a bit concerned about a tri-bool setting, specifically that users will keep asking for different combinations, at which point individual boolean settings probably becomes easier. However, ideally we'd keep the one boolean setting and just remove the docstring restriction or have it be its own rule (that is pedantic and either requires a docstring or forbids a docstring)
I didn't remember discussing this in particular, and I could only find the quote from the PR summary shown here. It also seems okay to me just to remove the docstring restriction. That's definitely the simplest approach.
Activity
ntBre commentedon Aug 3, 2026
I'm not opposed to it, as I guess I said on the PR 😄 I think some people really do prefer totally empty
__init__.pyfiles, though, so some kind of three-state config option might be needed, as you said. But I'm curious what others think.MichaReiser commentedon Aug 4, 2026
@ntBre do you remember if this is something we discussed when we added the rule? I tried to find some additional context on why the upstream rule denied docstrings but it seems to have been this way since the beginning.
I am a bit concerned about a tri-bool setting, specifically that users will keep asking for different combinations, at which point individual boolean settings probably becomes easier. However, ideally we'd keep the one boolean setting and just remove the docstring restriction or have it be its own rule (that is pedantic and either requires a docstring or forbids a docstring)
ntBre commentedon Aug 4, 2026
I didn't remember discussing this in particular, and I could only find the quote from the PR summary shown here. It also seems okay to me just to remove the docstring restriction. That's definitely the simplest approach.
[`ruff`] Allow docstrings in strict mode (`RUF067`) (#28679)