-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Relax protected namespace config default #10441
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 files reviewed, 1 outstanding issue(s) found.
Deploying pydantic-docs with
|
Latest commit: |
36a7816
|
Status: | ✅ Deploy successful! |
Preview URL: | https://5749a93c.pydantic-docs.pages.dev |
Branch Preview URL: | https://protected-ns.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10441 will not alter performanceComparing Summary
|
231eb93
to
e9d3e43
Compare
changing tests, adding updates remove added space Update docs/concepts/serialization.md Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> Update docs/concepts/serialization.md Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com> removing warning related code
removing unneeded warning check
1859a35
to
0a9bfa9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one real question, otherwise LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 files reviewed, 2 total issue(s) found.
I think this should be ready for review. Given #10493, I actually don't think it's necessary that we add from pydantic import BaseModel
from typing import Any
class User(BaseModel):
model_fields: list[str]
model_computed_fields: list[str]
model_extra: dict[str, Any]
model_fields_set: set[str]
user = User(model_fields=['id', 'name'], model_computed_fields=[], model_extra={}, model_fields_set={'id', 'name'})
"""
/Users/programming/pydantic_work/pydantic/pydantic/_internal/_fields.py:190: UserWarning: Field name "model_fields" in "User" shadows an attribute in parent "BaseModel"
warnings.warn(
/Users/programming/pydantic_work/pydantic/pydantic/_internal/_fields.py:190: UserWarning: Field name "model_computed_fields" in "User" shadows an attribute in parent "BaseModel"
warnings.warn(
/Users/programming/pydantic_work/pydantic/pydantic/_internal/_fields.py:190: UserWarning: Field name "model_extra" in "User" shadows an attribute in parent "BaseModel"
warnings.warn(
/Users/programming/pydantic_work/pydantic/pydantic/_internal/_fields.py:190: UserWarning: Field name "model_fields_set" in "User" shadows an attribute in parent "BaseModel"
warnings.warn(
""" I've also enabled support for compiled patterns, though I don't think that's necessary, as all other overrides are methods - which are standard practice to override, and you'll get type checking warnings if signature isn't compatible or b) warnings if something conflicts with the protected namespaces. |
@@ -273,7 +273,7 @@ def push(self, config_wrapper: ConfigWrapper | ConfigDict | None): | |||
ser_json_inf_nan='null', | |||
validate_default=False, | |||
validate_return=False, | |||
protected_namespaces=('model_',), | |||
protected_namespaces=('model_validate', 'model_dump'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to add model_construct
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, cc @samuelcolvin @dmontagu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up here - we decided we didn't need to add model_construct
- that's not a namespace we anticipate expanding in the same way we do for model_dump_
etc, you can imagine python
, json
, some_other_format
.
Closes #10315
Decided not to warn on method overrides, as that's an incredibly common practice in Python, and type checking does enough warning here in cases of incompatibility.