Skip to content

Adjust .as_optional_path() to return None for empty strings - #223

Merged
snejus merged 1 commit into
mainfrom
as-optional-path-empty-string-as-none
Nov 1, 2026
Merged

snejus merged 1 commit into
mainfrom
as-optional-path-empty-string-as-none

Conversation

@snejus

@snejus snejus commented Oct 25, 2026

Copy link
Copy Markdown
Member

Summary

as_optional_path() treated an empty string as a relative path. Filename.value joins any non-absolute value with the config/source directory and then calls os.path.abspath, so foo: "" resolved to that directory itself instead of returning None (confuse/templates.py:717-738). An empty config entry is almost always "unset", not "point at the config dir".

This branch makes as_optional_path() return None for an empty string, so empty and missing/null values now behave the same (confuse/core.py:334-342).

Tests

  • test_as_optional_path gains a ({"foo": ""}, None) case alongside the existing None and missing-key cases (test/test_validation.py:73).

@snejus
snejus requested review from JOJ0 and amogus07 and a balanced review from Copilot October 25, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@snejus
snejus force-pushed the as-optional-path-empty-string-as-none branch from 6f0c0ea to 6b94a72 Compare October 25, 2026 19:16

@JOJ0 JOJ0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You want to make sure that bytes paths stay supported, that is the case. But should an empty bytes path(b"") then also be handled as None?

Not sure if that's very relevant but it would be more consistent, right?

Comment thread test/test_validation.py Resolved
Add early return when value is falsy to handle empty strings
consistently with None values. Update docstring to clarify behavior and
add test case for empty string input.
@snejus
snejus force-pushed the as-optional-path-empty-string-as-none branch from 6b94a72 to 55fb6f4 Compare October 30, 2026 12:59
@snejus
snejus merged commit 16e782f into main Nov 1, 2026
15 checks passed
@snejus
snejus deleted the as-optional-path-empty-string-as-none branch November 1, 2026 14:17
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.

3 participants