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

Support Path as a field type #40

Closed
mthuurne opened this issue Aug 17, 2023 · 1 comment · Fixed by #42
Closed

Support Path as a field type #40

mthuurne opened this issue Aug 17, 2023 · 1 comment · Fixed by #42
Labels
enhancement New feature or request

Comments

@mthuurne
Copy link
Member

Services might want to configure paths, such as logging directories or locations of certificates. By supporting pathlib.Path as a field type:

  • it becomes explicit that a particular field represents a file system path
  • the code using the field doesn't have to convert from/to Path
  • we can generate a more specific template value
@mthuurne mthuurne added the enhancement New feature or request label Aug 17, 2023
@mthuurne
Copy link
Member Author

I was thinking of whether there could also be a way to have the binder perform additional checks, such as whether a referenced path exists. However, there are a lot of problems with that:

  • we'd need new syntax to specify the additional checks to perform, which goes against the idea of using plain dataclasses as much as possible; while I see this as more of a guideline than a hard rule, there would have to be strong advantages to breaking it
  • it doesn't save the developer much work: rejecting a non-existing or non-accessible path on startup doesn't release the code using it from the obligation to handle non-existing or non-accessible paths, as the file system could have changed between the initial check and the path actually being used
  • for some situations, like logging directories, the desired behavior could be to attempt to create the directory if it doesn't exist yet, but doing that as a side effect of data binding feels like overreach

So I think it's better not to do anything beyond constructing the Path object. If the developer wants to do more, __post_init__() can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant