Skip to content

Enable safe fallback when loading single values - #147

Draft
akaIDIOT wants to merge 4 commits into
mainfrom
feature/load-single-value-fallback
Draft

Enable safe fallback when loading single values#147
akaIDIOT wants to merge 4 commits into
mainfrom
feature/load-single-value-fallback

Conversation

@akaIDIOT

@akaIDIOT akaIDIOT commented Aug 7, 2026

Copy link
Copy Markdown
Member
  • needs reviewer(s) to agree with the implementation
  • needs changelog entry

Comment thread confidence/formats.py
with Path(fpath).open('rt', encoding=encoding or self.encoding) as fp:
return self.load(fp)

def loadv(self, string: str) -> typing.Any:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure this implementation is entirely kosher, thoughts welcome 🤔

This combined with calling it where singular values are expected does actually fairly transparently solve the issue.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Comparing median (lower is better) metric of benchmarks between this PR's target (562ed1c) and the HEAD of this PR (4d54ee9):

3.10 3.11 3.12 3.13 3.14 3.15 PyPy 3.10 PyPy 3.11
test_benchmark_get +2% -3% -4% +0% -1% +2% -2% +1%
test_benchmark_get_dotted -1% -1% -0% +2% -2% +4% -3% +0%
test_benchmark_getattr +2% -2% -3% +0% -1% +3% +1% +3%
test_benchmark_getitem +2% -2% -3% +1% -2% +2% +1% +2%
test_benchmark_getitem_dotted -2% -2% +0% +2% -3% -0% -5% -2%
test_benchmark_init_full_overlap +2% +3% -1% -1% -2% +0% -2% +1%
test_benchmark_init_no_overlap +2% +1% -0% -2% -2% -1% +0% +2%
test_benchmark_init_partial_overlap +3% +3% -1% -0% -1% +1% -2% +2%
test_benchmark_match_mapping +2% -1% -4% -0% -1% +2% +1% -0%
test_benchmark_reference_chain -2% +1% -2% -3% +2% +1% -1% +2%
test_benchmark_splat_args +1% +6% +0% -0% +1% +0% +5% +8%
test_benchmark_spread_kwargs -2% +2% +1% -1% -1% +4% +2% -0%

(This comment will be updated on subsequent pushes)

Comment thread confidence/formats.py

suffix: str = '' #: the default file path suffix for a configuration file of this Format
encoding: str = 'utf-8' #: the default text encoding for reading from binary I/O
value_fallback: Callable[[str], typing.Any] = str #: the fallback 'factory' for unparseable single values

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changing this needs a test

Comment thread confidence/formats.py

suffix: str = '' #: the default file path suffix for a configuration file of this Format
encoding: str = 'utf-8' #: the default text encoding for reading from binary I/O
value_fallback: Callable[[str], typing.Any] = str #: the fallback 'factory' for unparseable single values

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Alternatively, we could so something like Format(strict=False), where the fallback type is always str. Less explicit, maybe easier to understand?

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.

1 participant