Skip to content

fix: allow DISC_NUMBER to be optional, matching DISC_TOTAL - #82

Open
Andreas-Garcia wants to merge 1 commit into
mainfrom
fix/disc-number-optional-type
Open

fix: allow DISC_NUMBER to be optional, matching DISC_TOTAL#82
Andreas-Garcia wants to merge 1 commit into
mainfrom
fix/disc-number-optional-type

Conversation

@Andreas-Garcia

Copy link
Copy Markdown
Member

Description

DISC_NUMBER's optional type was int-only, so files without a disc number failed unified-metadata schema validation, while DISC_TOTAL (also optional) validated fine.

Fixing that type surfaced two more bugs:

  • unified_metadata_field_schema.py special-cased DISC_TOTAL to report value_type: "integer" / optional_value: True, but relied on get_optional_type() is int for DISC_NUMBER — once DISC_NUMBER's optional type became int | None, that check silently fell through to "string" / optional_value: False. DISC_NUMBER now shares DISC_TOTAL's explicit branch.
  • UnifiedMetadataKey.get_optional_type() was annotated as returning type[int | float | str | list[str]], but its map already returned non-type runtime objects (e.g. int | float, and now int | None). Corrected the return annotation to object and narrowed with cast() at the one call site that requires a plain type for isinstance().

Split out of #80 as a standalone, independently-mergeable library bug fix (unrelated to that PR's content changes).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Tests

  • pytest audiometa/test/tests/unit/utils/test_unified_metadata_field_schema.py — 10 passed

DISC_NUMBER's type was int-only, so files without a disc number
failed schema validation while DISC_TOTAL (also optional) validated
fine. Fixing the type surfaced two more bugs: the field-schema
special-case for DISC_TOTAL relied on get_optional_type() is int,
which silently mis-reported DISC_NUMBER once its optional type
became int | None; and get_optional_type()'s return annotation
didn't match the non-type runtime values (e.g. int | float) it
already returned, so the isinstance() call site needed a cast().
Copilot AI lite review requested due to automatic review settings August 7, 2026 17:01
@github-actions github-actions Bot added documentation Improvements or additions to documentation test labels Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes unified-metadata schema/type handling so DISC_NUMBER is truly optional (nullable) in the same way as DISC_TOTAL, preventing schema validation regressions when a disc number is absent.

Changes:

  • Updated UnifiedMetadataKey.DISC_NUMBER optional type to int | None and corrected get_optional_type()’s return annotation to reflect non-type runtime values (unions / generic aliases).
  • Fixed field-schema generation to explicitly treat both DISC_NUMBER and DISC_TOTAL as value_type: "integer" with optional_value: True.
  • Added/updated unit tests covering the DISC_NUMBER schema descriptor and documented the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
CHANGELOG.md Documents the DISC_NUMBER optionality fix and the related schema/type-annotation corrections.
audiometa/utils/unified_metadata_key.py Makes DISC_NUMBER nullable and corrects get_optional_type() typing to match actual returned runtime objects.
audiometa/utils/unified_metadata_field_schema.py Ensures DISC_NUMBER is described as an optional integer in the wire schema, matching DISC_TOTAL.
audiometa/test/tests/unit/utils/test_unified_metadata_field_schema.py Adds regression coverage for DISC_NUMBER being an optional integer in the field schema.
audiometa/init.py Narrows expected_type to a plain type at the isinstance() call site via cast() to keep runtime checks valid.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants