-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Utils: add strict mode to load_file #13265
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
Conversation
Test Results (amd64) - Integration, Bootstrap 5 files 5 suites 2h 41m 32s ⏱️ Results for commit 5129ea4. ♻️ This comment has been updated with latest results. |
dfangl
left a comment
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.
I like this! I for example was not aware of this behavior of load_file, good catch!
|
|
||
| def load_file(file_path: str, default=None, mode=None): | ||
| def load_file( | ||
| file_path: str | os.PathLike, default: Any = None, mode: str | None = None, strict: bool = 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.
| file_path: str | os.PathLike, default: Any = None, mode: str | None = None, strict: bool = False | |
| file_path: str | os.PathLike, default: str | bytes | None = None, mode: str | None = None, strict: bool = False |
I think default should really only be str or bytes.
| def load_file(file_path: str, default=None, mode=None): | ||
| def load_file( | ||
| file_path: str | os.PathLike, default: Any = None, mode: str | None = None, strict: bool = 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.
| ): | |
| ) -> str | bytes: |
more typing 🎉
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.
Might also be worth adding a docstring explaining default vs strict and that the latter takes precedence?
9d8416e to
836617e
Compare
836617e to
5129ea4
Compare
Motivation
While reviewing a Pro PR I commented that
load_filemay returnNoneif the file does not exist. This behaviour may be confusing, and we should really strictly load a file, where handling the case of the missing file should be done by the caller.Changes
As a migration path, I added a
strictkwarg to the function so we can opt in to the strict behaviour. Potentially with the mind to making it strict by default in the future.In addition I migrated
deploy_cfn_templateto use this new strict mode since it is the most common source of annoyance for me.Next steps
I would like to rewrite call sites to use the strict mode to start migrating the default behaviour to be strict.