pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/145373

ubassets.com/assets/primer-primitives-ef1311e26457f1ec.css" /> gh-145369: Warn against reusing dataclass field objects by gourijain029-del · Pull Request #145373 · python/cpython · GitHub
Skip to content

gh-145369: Warn against reusing dataclass field objects#145373

Closed
gourijain029-del wants to merge 1 commit intopython:mainfrom
gourijain029-del:gh-145369-dataclass-field-reuse-warning
Closed

gh-145369: Warn against reusing dataclass field objects#145373
gourijain029-del wants to merge 1 commit intopython:mainfrom
gourijain029-del:gh-145369-dataclass-field-reuse-warning

Conversation

@gourijain029-del
Copy link

@gourijain029-del gourijain029-del commented Feb 28, 2026

Adds a warning to the dataclasses documentation explaining that field objects should not be reused across multiple fields or classes.

The issue is that field() returns an object that gets modified in place by the @DataClass decorator. If you reuse the same field object, it becomes corrupted and causes the class to behave incorrectly.

The warning includes:

  • Clear explanation of why reusing is problematic
  • Example showing the incorrect pattern
  • Example showing the correct approach

Fixes #145369


📚 Documentation preview 📚: https://cpython-previews--145373.org.readthedocs.build/

…reused

Add warning to dataclasses documentation explaining that Field objects
returned by field() should not be reused across multiple fields or
classes, as they are modified in place by the decorator.
@picnixz
Copy link
Member

picnixz commented Feb 28, 2026

  • A warning is too loud.
  • This shouldn't be documented in the dataclass section IMO. It's the regular behavior.
  • Please read https://devguide.python.org/getting-started/generative-ai/ and avoid using language that may convene hestiation.
  • Please don't open a PR unless an issue has been triaged by a triager or a maintainer.

@picnixz picnixz closed this Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Document dataclass field should not be reused

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy