-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Clean up Field parameters #5425
Conversation
please review |
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.
otherwise LGTM.
Might be work asking @dmontagu about why he made the default of frozen=None
.
please update.
pydantic/fields.py
Outdated
@@ -375,16 +379,18 @@ def Field( | |||
of digits within the decimal. It does not include a zero before the decimal point or trailing decimal zeroes. | |||
:param decimal_places: only applies to Decimals, requires the field to have at most a number of decimal places | |||
allowed. It does not include trailing decimal zeroes. | |||
:param min_items: only applies to lists, requires the field to have a minimum number of | |||
:param min_items: deprecated, use ``min_length`` instead. |
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.
we want to use single back-ticks since this will be rendered as markdown - might as well fix the whole docstring now.
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.
Fixed for all docstrings in code
pydantic/fields.py
Outdated
# Check deprecated & removed params of V1. | ||
# This has to be removed deprecation period over. | ||
if const: | ||
raise ValueError('`const` is removed. use `Literal` instead') |
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.
Please use PydanticUserError
, add a code and a section to docs if you think necessary, otherwise set code=None
.
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.
Done. field-removed-param
error code defined
pydantic/fields.py
Outdated
raise ValueError('`const` is removed. use `Literal` instead') | ||
if min_items: | ||
warn('`min_items` is deprecated and will be removed. use `min_length` instead', DeprecationWarning) | ||
min_length = min_items |
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.
if min_length is None
.
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.
and below.
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 catch. done
pydantic/fields.py
Outdated
warn('`max_items` is deprecated and will be removed. use `max_length` instead', DeprecationWarning) | ||
max_length = max_items | ||
if unique_items: | ||
raise ValueError('`unique_items` is removed. use `Set` instead') |
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.
raise ValueError('`unique_items` is removed. use `Set` instead') | |
raise ValueError('`unique_items` is removed, use `Set` instead') |
Might be worth adding (this feature is discussed in https://github.com/pydantic/pydantic-core/issues/296)
tests/test_annotated.py
Outdated
@@ -22,22 +22,22 @@ | |||
( | |||
lambda: Annotated[int, Field(gt=0)], | |||
5, | |||
'FieldInfo(annotation=int, required=False, default=5, metadata=[Gt(gt=0)])', | |||
'FieldInfo(annotation=int, required=False, default=5, metadata=[Gt(gt=0)], frozen=False)', |
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.
if we set the default of frozen to False
, we should ignore frozen=False
in repr.
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.
ignored
1d6a7e7
to
115bd8d
Compare
please review |
I don't think this was super intentional. I think I may have been following the pattern used for And given the following snippet from the docstring, I think :param allow_inf_nan: only applies to numbers, allows the field to be NaN or infinity (+inf or -inf),
which is a valid Python float. Default True, set to False for compatibility with JSON. |
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.
otherwise LGTM.
please update.
115bd8d
to
de1e21e
Compare
please review |
this is great, thank you. |
Change Summary
Clean up Field parameters
Related issue number
Fixes #5406
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)
Selected Reviewer: @samuelcolvin