Navigation Menu

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

Allow to configure models through class kwargs #2356

Merged

Conversation

Bobronium
Copy link
Contributor

@Bobronium Bobronium commented Feb 13, 2021

Change Summary

Allow to configure models through class kwargs

from pydantic import BaseModel

class Model(BaseModel, extra='allow'):
    foo: int
    bar: int

Related issue number

Closes #2330

Implementation details

Any kwargs that are passed into class and match attrs of BaseConfig will be included in config.
All unused kwargs will be passed to type untouched so #867 won't break.

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)

@Bobronium Bobronium changed the title Configure models through class kwargs Allow to configure models through class kwargs Feb 13, 2021
@codecov
Copy link

codecov bot commented Feb 13, 2021

Codecov Report

Merging #2356 (6996ffb) into master (fc18f8e) will decrease coverage by 0.80%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master    #2356      +/-   ##
==========================================
- Coverage   99.97%   99.17%   -0.81%     
==========================================
  Files          23       23              
  Lines        4500     4485      -15     
  Branches      909      909              
==========================================
- Hits         4499     4448      -51     
- Misses          1       27      +26     
- Partials        0       10      +10     
Impacted Files Coverage Δ
pydantic/typing.py 83.01% <82.14%> (-16.41%) ⬇️
pydantic/_hypothesis_plugin.py 100.00% <100.00%> (ø)
pydantic/annotated_types.py 100.00% <100.00%> (ø)
pydantic/fields.py 100.00% <100.00%> (ø)
pydantic/schema.py 100.00% <100.00%> (ø)
pydantic/validators.py 100.00% <100.00%> (ø)
pydantic/version.py 88.23% <0.00%> (-11.77%) ⬇️
pydantic/env_settings.py 98.41% <0.00%> (-1.59%) ⬇️
pydantic/networks.py 98.52% <0.00%> (-1.48%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc18f8e...f9bfb30. Read the comment docs.

@samuelcolvin samuelcolvin merged commit ce67660 into pydantic:master Feb 22, 2021
@samuelcolvin
Copy link
Member

thank you so much, this is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure models through class kwargs
2 participants