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

Add validation for number of datetimes in Temporal.interval #17

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mo-lukecarr
Copy link

@@ -13,8 +15,7 @@ class Spatial(EdrBaseModel):


class Temporal(EdrBaseModel):
# TODO: Validate this list has two items (C.7. Temporal Object)
interval: List[List[AwareDatetime]]
interval: List[Annotated[List[AwareDatetime], Len(min_length=2, max_length=2)]]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: add some test cases to confirm that validation fails when lists are provided with len(...) != 2.

@mo-lukecarr
Copy link
Author

I appear to get an error in IntelliJ on the use of Len(...) which says Generics should be specified through square brackets. However, tests are still passing locally and a quick search suggests that this is a known issue with JetBrains' inspections (e.g. non-issue).

@PaulVanSchayck
Copy link
Collaborator

Thanks for this draft PR. You probably need to add this snippet to make Python 3.8 happy:

if sys.version_info < (3, 9):
    from typing_extensions import Annotated
else:
    from typing import Annotated

@mo-lukecarr
Copy link
Author

Thanks for this draft PR. You probably need to add this snippet to make Python 3.8 happy:

if sys.version_info < (3, 9):
    from typing_extensions import Annotated
else:
    from typing import Annotated

My impression (maybe wrong!) is that typing_extensions can be a drop-in for all versions, so I could amend the import to just use from typing_extensions import Annotated for all versions, rather than checking sys.version_info and conditionally importing.

Or is there a specific preference to use this approach? Happy to do so if there is!

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.

2 participants