Skip to content

Conversation

@simonrw
Copy link
Contributor

@simonrw simonrw commented Oct 14, 2025

Motivation

While reviewing a Pro PR I commented that load_file may return None if 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 strict kwarg 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_template to 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.

@simonrw simonrw added semver: patch Non-breaking changes which can be included in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Oct 14, 2025
@github-actions
Copy link

github-actions bot commented Oct 14, 2025

Test Results - Preflight, Unit

22 338 tests  +1   20 588 ✅ +1   15m 16s ⏱️ -16s
     1 suites ±0    1 750 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 5129ea4. ± Comparison against base commit 1913637.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 14, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 26s ⏱️ -1s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 5129ea4. ± Comparison against base commit 1913637.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 14, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   2h 41m 32s ⏱️
5 245 tests 4 730 ✅ 515 💤 0 ❌
5 251 runs  4 730 ✅ 521 💤 0 ❌

Results for commit 5129ea4.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 14, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   2h 0m 52s ⏱️ -36s
4 871 tests ±0  4 516 ✅ ±0  355 💤 ±0  0 ❌ ±0 
4 873 runs  ±0  4 516 ✅ ±0  357 💤 ±0  0 ❌ ±0 

Results for commit 5129ea4. ± Comparison against base commit 1913637.

♻️ This comment has been updated with latest results.

@simonrw simonrw marked this pull request as ready for review October 14, 2025 14:51
@simonrw simonrw requested a review from dfangl October 14, 2025 14:51
Copy link
Member

@dfangl dfangl left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
):
) -> str | bytes:

more typing 🎉

Copy link
Member

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?

@simonrw simonrw force-pushed the utils/load-file/strict-mode branch from 9d8416e to 836617e Compare October 16, 2025 14:03
@simonrw simonrw force-pushed the utils/load-file/strict-mode branch from 836617e to 5129ea4 Compare October 16, 2025 14:04
@simonrw simonrw merged commit 1603c68 into main Oct 16, 2025
39 checks passed
@simonrw simonrw deleted the utils/load-file/strict-mode branch October 16, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants