Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Fix: init=False in dataclass fields ignored #8545

Closed

Commits on Jan 13, 2024

  1. Partial Fix: init=False in dataclass fields ignored

    Why
    - Previously, setting `init=False` in std field and pydantic's Field had
    no effect, the field still appears as a parameter in the generated `__init__`
    
    What
    - Added `init` attribute to `FieldInfo` and `Field`
    - Corrected docstring for `init_var`
    - Added check for `init` in `make_pydantic_fields_compatible`
    - Added test to confirm `init=False` fields don't show up in the signature
    
    Notes
    - Unfortunately, can still use the `init=False` as parameters in init...
    I think this is because of pydantic allowing the "extra" params that aren't
    explicitly defined
    - Even setting `ConfigDict(extra='forbid')` doesn't help here. From some
    debugging, it doesn't look like the model schema understands the `init=False`.
    So more work needed to actually throw an error.
    tigeryy2 committed Jan 13, 2024
    Configuration menu
    Copy the full SHA
    eea1b40 View commit details
    Browse the repository at this point in the history