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
The underscore_attrs_are_private config flag turns __doc__ attribute into a ModelPrivateAttr #2090
Closed
3 tasks done
Labels
bug V1
Bug related to Pydantic V1.X
Comments
Hi @jstavrak class DocPreservingModelMetaclass(ModelMetaclass):
def __new__(mcs, name, bases, namespace, **kwargs):
doc = namespace.pop('__doc__', None)
cls = super().__new__(mcs, name, bases, namespace, **kwargs)
cls.__doc__ = doc
return cls Have a good day |
samuelcolvin
pushed a commit
that referenced
this issue
Nov 4, 2020
Hi guys, Thanks for the immediate reply, fix, and simplification of the metaclass offered! Have a nice day! |
samuelcolvin
pushed a commit
that referenced
this issue
Nov 30, 2020
samuelcolvin
added a commit
that referenced
this issue
Jan 1, 2021
* fix: ignore `__doc__` as valid private attribute (#2091) closes #2090 * Fixes a regression where Enum fields would not propagate keyword arguments to the schema (#2109) fix #2108 * Fix schema extra not being included when field type is Enum * Code format * More code format * Add changes file Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk> * fix: update all modified field values in `root_validator` when `validate_assignment` is on (#2119) * fix: update all modified field values in `root_validator` when `validate_assignment` is on closes #2116 * chore: update root_validator name Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> * fix: support `underscore_attrs_are_private` with generic models (#2139) closes #2138 * fix: set right default value for required (optional) fields (#2143) closes #2142 * Fix #2111: support pickle for built-in dataclasses (#2114) * 2111: support pickle for built-in dataclasses * 2111: add changes * 2111: simplify test * return original name + handle similar names * add additional check * fix a misspell * remove useless f-string * cleanup test Co-authored-by: Samuel Colvin <s@muelcolvin.com> * uprev and add history * tempoarily pin pip Co-authored-by: Eric Jolibois <em.jolibois@gmail.com> Co-authored-by: Ben Martineau <bm424@cam.ac.uk> Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk> Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com> Co-authored-by: aimestereo <aimestereo@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Pydantic v1.7 introduced the private attributes. But when the config flag
underscore_attrs_are_private
is set toTrue
, the model's__doc__
attribute also becomes a private attribute. Example:My current workaround is to define a new metaclass to handle the issue:
But maybe it would be best if
__doc__
was excluded viapydantic.utils.is_valid_private_name
, much like the other standard properties are excluded through this method. However, I am not sure if the latter will have other implication in the current codebase.The text was updated successfully, but these errors were encountered: