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

chore: check not None path on datasamplespec #395

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

ThibaultFy
Copy link
Member

Related issue

# followed by the number of the issue

Summary

Notes

Please check if the PR fulfills these requirements

  • If necessary, the changelog has been updated
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • The commit message follows the conventional commit specification
  • For any breaking changes, companion PRs have been opened on the following repositories:

Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
@ThibaultFy ThibaultFy marked this pull request as ready for review November 2, 2023 14:12
@ThibaultFy ThibaultFy requested a review from a team as a code owner November 2, 2023 14:12
Copy link
Contributor

@guilhem-barthes guilhem-barthes left a comment

Choose a reason for hiding this comment

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

Thank for your work, some comments on typing ^^

Nitpick: If path or paths are expected to be existing dirs, we could use pydantic.DirectoryPath (https://docs.pydantic.dev/latest/api/types/#pydantic.types.DirectoryPath)

These changes may be need to be checked on Windows (but has we never cast to PosixPath, I expect it won't break anything)

@@ -146,6 +146,30 @@ class DataSampleSpec(_Spec):
def is_many(self):
return self.paths and len(self.paths) > 0

@pydantic.field_validator("paths")
@classmethod
def resolve_paths(cls, v: typing.Any) -> typing.Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def resolve_paths(cls, v: typing.Any) -> typing.Any:
def resolve_paths(cls, v: Optional[List[pathlib.Path]]) -> Optional[List[pathlib.Path]]:

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh great. And I removed the "optional" in that case, as, if the field is specified, this is not optional anymore to have a path. WDT ?


@pydantic.field_validator("path")
@classmethod
def resolve_path(cls, v: typing.Any) -> typing.Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def resolve_path(cls, v: typing.Any) -> typing.Any:
def resolve_path(cls, v: Optional[pathlib.Path]) -> Optional[pathlib.Path]:


paths = []
for path in v:
path = pathlib.Path(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
path = pathlib.Path(path)

pydantic already casts str to path when using the type pathlib.Path

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I didn't knew ! So nice...

Comment on lines 156 to 161
paths = []
for path in v:
path = pathlib.Path(path)
paths.append(path.resolve())

return paths
Copy link
Contributor

@guilhem-barthes guilhem-barthes Nov 2, 2023

Choose a reason for hiding this comment

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

nitpick: style change, you can disregard

Suggested change
paths = []
for path in v:
path = pathlib.Path(path)
paths.append(path.resolve())
return paths
return [p.resolve() for p in paths]

if v is None:
raise ValueError("'path' cannot be set to None.")

path = pathlib.Path(v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
path = pathlib.Path(v)

Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
Copy link
Contributor

@guilhem-barthes guilhem-barthes left a comment

Choose a reason for hiding this comment

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

LGTM

@ThibaultFy ThibaultFy merged commit ef2482d into main Feb 28, 2024
6 checks passed
@ThibaultFy ThibaultFy deleted the chore/check-not-none-datasamplespec branch February 28, 2024 16:46
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