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

Dataclass extra #3393

Closed
wants to merge 3 commits into from
Closed

Conversation

DetachHead
Copy link
Contributor

@DetachHead DetachHead commented Nov 5, 2021

Change Summary

forked from @PrettyWood's change which allows using the extra config option for dataclasses.

see #986 (comment)

Related issue number

fix #986

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@DetachHead
Copy link
Contributor Author

please review

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reopened the original issue, no idea why I closed it, must have been a mistake.

I'm also a bit confused about why tests weren't run, hopefully if you commit again they'll be triggered.

a: str
b: str

Foo(**{"a": "bar", "b": "foo", "c": 1})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • single quotes
  • Foo(a='bar'...) would be cleaner
  • you need to add assert not hasattr(foo, 'c')
  • you need to add another test for Extra.allow

k: v for k, v in kwargs.items() if k in get_type_hints(type(self))
})

cls.__original_init__ = cls.__init__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is never called. We need a test for this.

})

cls.__original_init__ = cls.__init__
cls.__init__ = allow_extra_init
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PrettyWood I remember we had lots of problems with overriding __init__ at some points.

Do you think this will break anything?

What about conflicts with #2557, will it just be code conflicts, or does this approach need to be rethought?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry @DetachHead but I felt like it was way easier to add it in 30b58f3 rather than handling conflicts :/

@samuelcolvin IMO if the commit above is good we can close this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PrettyWood looks good. though i can't find the branch that commit is on? is there a PR for it?

@samuelcolvin
Copy link
Member

please update.

@DetachHead
Copy link
Contributor Author

closing since #2557 was merged

@DetachHead DetachHead closed this Aug 5, 2022
@DetachHead DetachHead deleted the dataclass-extra branch August 8, 2022 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pydantic dataclasses do not respect the extra-fields in Config
3 participants