Skip to content

RUF067 allow docstrings in __init__.py in strict mode #27416

Closed

Description

@brianmaissy

Summary

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.

Activity

  1. ntBre commented on Aug 3, 2026

    @ntBre
    Contributor

    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.

  2. added
    rule
    preview
    on Aug 3, 2026
  3. MichaReiser commented on Aug 4, 2026

    @MichaReiser
    Member

    @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)

  4. added
    configuration
    on Aug 4, 2026
  5. ntBre commented on Aug 4, 2026

    @ntBre
    Contributor

    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.

  6. added a commit that references this issue on Oct 1, 2026
    9c37f03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    configurationpreviewrule

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions