Skip to content

Minor mistake in dataclasses documentation update #108267

Description

@FrozenBob

An update to the dataclasses docs, intended to make magic method names link to the relevant data model documentation, accidentally changed a line that shouldn't have been changed.

The docs used to say

There is a tiny performance penalty when using frozen=True: __init__() cannot use simple assignment to initialize fields, and must use object.__setattr__().

The documentation update accidentally changed object.__setattr__ to just __setattr__ here, so now it reads

There is a tiny performance penalty when using frozen=True: __init__() cannot use simple assignment to initialize fields, and must use __setattr__().

This line was specifically meant to refer to object.__setattr__, the __setattr__ method of the base object class, as simple attribute assignment would hit the frozen dataclass's __setattr__ override.

This part of the documentation should be reverted. I think it should just take a 1-character change, simply removing a tilde.

Linked PRs

Activity

  1. ericvsmith commented on Aug 22, 2023

    @ericvsmith
    Member

    I'm no sphinx expert. Would removing a tilde restore the output text to be object.__setattr__? That's what I think should be displayed.

  2. hugovk commented on Aug 22, 2023

    @hugovk
    Member

    Yes, removing the tilde gives object.__setattr__():

    image

    @FrozenBob Thanks for the report, would you like to create a PR to fix this?

  3. added
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    on Aug 22, 2023
  4. ericvsmith commented on Aug 22, 2023

    @ericvsmith
    Member

    Yes, removing the tilde gives object.__setattr__():

    How on earth is someone supposed to know that? Seriously: where could I find out more info? I'd like to get better at this.

  5. AlexWaygood commented on Aug 22, 2023

    @AlexWaygood
    Member

    @ericvsmith there's some useful info on the markup in the devguide here (in particular, see the "quick reference" section at the top of the page): https://devguide.python.org/documentation/markup/

  6. AlexWaygood commented on Aug 22, 2023

    @AlexWaygood
    Member

    If we just remove the tilde, the link will take people to the entry in the data model documentation for the __setattr__ magic method, rather than the docs for object.__setattr__ itself (we have no docs for object.__setattr__ itself). Maybe it would be better in this case to suppress the link entirely?

    :meth:`!object.__setattr__`

    That will render as object.__setattr__() in the HTML documentation, but won't add a link.

  7. FrozenBob commented on Aug 22, 2023

    @FrozenBob
    ContributorAuthor

    Suppressing the link sounds reasonable to me.

  8. ericvsmith commented on Aug 22, 2023

    @ericvsmith
    Member

    Suppressing the link sounds reasonable to me.

    Agreed.

  9. added a commit that references this issue on Aug 23, 2023
  10. added 2 commits that reference this issue on Aug 23, 2023
  11. added a commit that references this issue on Aug 23, 2023
  12. 12 remaining items

  13. added 2 commits that reference this issue on May 16, 2024
  14. FrozenBob commented on May 17, 2024

    @FrozenBob
    ContributorAuthor

    I think you might need an extra blank line before the comment or something - it's rendering in the generated documentation.

  15. FrozenBob commented on May 17, 2024

    @FrozenBob
    ContributorAuthor

    I see a confused emoji. In case it wasn't clear, this is what's showing up in the docs now:

    There is a tiny performance penalty when using frozen=True: __init__() cannot use simple assignment to initialize fields, and must use object.__setattr__(). .. Make sure to not remove “object” from “object.__setattr__” in the above markup

    The part starting with the ".." looks like it was supposed to be a reStructuredText comment, but it's showing up in the actual documentation. I think this may be because it needs a blank line above it.

  16. AlexWaygood commented on May 17, 2024

    @AlexWaygood
    Member

    I understood the problem — sorry for the ambiguous reaction emoji I applied! I suppose I intended to convey that I was frustrated at myself for not checking the docs preview before merging, but sadly there's no reaction emoji for that exact sentiment ;-)

  17. added 2 commits that reference this issue on May 20, 2024
  18. added 2 commits that reference this issue on May 20, 2024
  19. added 2 commits that reference this issue on May 20, 2024
  20. added 2 commits that reference this issue on Jul 17, 2024
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

    3.11only security fixes3.12only security fixes3.13only security fixesdocsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions