-
Notifications
You must be signed in to change notification settings - Fork 0
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
🚧 Some improvements for Coordinate
type PR
#2
🚧 Some improvements for Coordinate
type PR
#2
Conversation
ceb992b
to
6440acd
Compare
35a45d8
to
b5e7993
Compare
6440acd
to
4bc6007
Compare
4bc6007
to
ed74ea4
Compare
Thanks @lig On my side I've change your implementation to this (parse_args -> parse_str -> parse_tuple) but latitude, longitude validation no longer works. WDYT?
|
2ae4694
to
af1a98d
Compare
9f627d7
to
074d27c
Compare
pydantic_extra_types/coordinate.py
Outdated
if n_args == 0: | ||
value = cls._NULL_ISLAND | ||
elif n_args == 1: | ||
value = value.args[0] |
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.
On my branch I've modified this part to add a default latitude, otherwise we'll get an error
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.
This is an error about the error case that is needed. We get an error for case like (20.0,)
that is a tuple with a single value. This case is in tests as invalid.
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.
You’re right but maybe we can raise an error directly, WDYT?
f626e0c
to
599a4e6
Compare
7d5fd0d
to
4d21b4d
Compare
I've updated the function def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:
return core_schema.no_info_wrap_validator_function(
cls._parse_args,
core_schema.no_info_wrap_validator_function(
cls._parse_str,
core_schema.chain_schema(
[
core_schema.no_info_wrap_validator_function(
cls._parse_tuple, handler.generate_schema(Tuple[Latitude, Longitude])
),
handler(source),
]
),
),
) Schema:
|
599a4e6
to
13cacb6
Compare
4d21b4d
to
b441a0b
Compare
] | ||
), | ||
core_schema.union_schema( | ||
[core_schema.chain_schema(schema_chain[2 - x :]) for x in range(3)], |
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.
Thanks for your help, but I don't understand why range(3)
and schema_chain[2 - x :]
?
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.
The full schema chain includes all three steps of conversion.
We allow entering this chain of transformations from any step. Thus we generate something that could be simplified like this: union([chain([3]), chain([2, 3]), chain([1, 2, 3])])
.
@JeanArhancet Sorry, I was ill. Now I'm back:) I've updated my changes. The idea here is that we accept three forms of coordinate for validation and using a canonical form for serialization. This is reflected in the schema being generated for this type (see In my opinion representing Coordinate as object by default for serialization is more useful for further processing data by external consumers, e.g. SPA Web App. It's possible to implement another type, i.e. Please, notice that schema generation requires |
I understand better thanks a lot. Maybe we can create a variable to explain this 3 ? |
Indeed, it could be more readable and robust to do something like this: Could you please take it from here on your PR? |
0a79122
into
JeanArhancet:feat/add-coordinate-latitude-longitude
* feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
* feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
* feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
* feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Add `Latitude`, `Longitude` and `Coordinate` (pydantic#76) * feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> ✨ add ulib type refactor: delete init function
Add `Latitude`, `Longitude` and `Coordinate` (pydantic#76) * feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> ✨ add ulib type refactor: delete init function
Add `Latitude`, `Longitude` and `Coordinate` (pydantic#76) * feat: add latitude, longitude and coordinate * refactor: apply feedbacks * refactor: apply feedbacks * refactor: delete __init__ functions * fix: coordinate parsing * docs: update coordinate documentation * refactor: use latitude, longitude in schema * 🚧 Some improvements for `Coordinate` type PR (#2) * refactor: delete __init__ functions * 🚧 Some improvements for `Coordinate` type PR * Get tests passing * ✨ Test serialization json schema * ⬆ Upgrade deps in `pyproject.toml` and `requirements/pyproject.txt --------- Co-authored-by: JeanArhancet <jean.arhancetebehere@gmail.com> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * fix: test and requirements * docs: fix supported format --------- Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> ✨ add ulib type refactor: delete init function
No description provided.