Skip to content

Add as_optional_path accessor - #202

Open
snejus wants to merge 1 commit into
mainfrom
add-as-optional-path
Open

Add as_optional_path accessor#202
snejus wants to merge 1 commit into
mainfrom
add-as-optional-path

Conversation

@snejus

@snejus snejus commented Aug 27, 2026

Copy link
Copy Markdown
Member

As I've been migrating beets to pathlib I realised that I use this pattern a lot:

$ grep -RiC1 'Optional.*Path' beets*
beetsplug/convert.py-    def tmpdir(self) -> Path | None:
beetsplug/convert.py:        return self.config["tmpdir"].get(confuse.Optional(confuse.Path()))
beetsplug/convert.py-
--
beetsplug/duplicates.py-        checksum = self.config["checksum"].get(str)
beetsplug/duplicates.py:        copy = self.config["copy"].get(confuse.Optional(confuse.Path()))
beetsplug/duplicates.py-        count = self.config["count"].get(bool)
--
beetsplug/duplicates.py-        merge = self.config["merge"].get(bool)
beetsplug/duplicates.py:        move = self.config["move"].get(confuse.Optional(confuse.Path()))
beetsplug/duplicates.py-        path = self.config["path"].get(bool)
--
beetsplug/fetchart.py-        return self.config["fallback"].get(
beetsplug/fetchart.py:            confuse.Optional(confuse.templates.Path())
beetsplug/fetchart.py-        )
--
beetsplug/importfeeds.py-        if feeds_dir := self.config["dir"].get(
beetsplug/importfeeds.py:            confuse.Optional(confuse.Path())
beetsplug/importfeeds.py-        ):
--
beetsplug/importfeeds.py-        if relative_to := self.config["relative_to"].get(
beetsplug/importfeeds.py:            confuse.Optional(confuse.Path())
beetsplug/importfeeds.py-        ):
--
beetsplug/play.py-        if relative_to := config["play"]["relative_to"].get(
beetsplug/play.py:            confuse.Optional(confuse.Path())
beetsplug/play.py-        ):
--
beetsplug/smartplaylist.py-        if relative_to := self.config["relative_to"].get(
beetsplug/smartplaylist.py:            confuse.Optional(confuse.Path())
beetsplug/smartplaylist.py-        ):

@snejus
snejus requested review from semohr and wisp3rwind and a lite review from Copilot and removed request for Copilot August 27, 2026 10:04
@github-actions

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@snejus
snejus force-pushed the add-as-optional-path branch from af4aeab to 51a90d6 Compare August 27, 2026 10:05
Copilot AI lite review requested due to automatic review settings August 27, 2026 10:05

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.

Pull request overview

This pull request adds a convenience accessor to retrieve optional path configuration values as pathlib.Path | None, aligning with common usage patterns during pathlib migration work.

Changes:

  • Add as_optional_path() accessor implemented via Optional(Path()).
  • Update validation tests to cover the new accessor and simplify as_path() testing now that pathlib is unconditionally available.
  • Document the change in the changelog and tune Ruff’s flake8-pytest-style configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
confuse/core.py Adds the new as_optional_path() accessor (wrapper around Optional(Path())).
test/test_validation.py Adds tests for as_optional_path() and simplifies as_path() test logic.
docs/changelog.rst Notes the new accessor in the Unreleased changelog.
pyproject.toml Adds Ruff flake8-pytest-style configuration adjustments.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread confuse/core.py
Comment thread test/test_validation.py
@snejus
snejus force-pushed the add-as-optional-path branch from 51a90d6 to e58c0e5 Compare August 27, 2026 10:18
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.

2 participants