Skip to content

Resolve wildcard classifiers in FileSet.convertible_from() - #166

Merged
tclose merged 2 commits into
mainfrom
resolve-convertible-from-wildcards
Oct 19, 2026
Merged

tclose merged 2 commits into
mainfrom
resolve-convertible-from-wildcards

Conversation

@tclose

@tclose tclose commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

convertible_from() included the unresolved source types of generic converters (e.g. SetOf[T], DirectoryOf[T] in FileSet.convertible_from()). These can't be instantiated, so sourcing items through the union failed with FormatDefinitionError (seen in frametree). It also left out sources that get_converter() can actually use, e.g. Zip[TextFile] for TextFile.

Changes

  • Source types with unresolved wildcard classifiers are no longer included.

  • The wildcards of generic converters are resolved from the target type:

    • Zip[Compressed] → Compressed (and Tar, TarGzip): TextFile is convertible from Zip[TextFile] etc.
    • SetOf[T] → DirectoryOf[T]: DirectoryOf[TextFile] is convertible from SetOf[TextFile].
    • Compressed → Zip[Compressed]: Zip[TextFile] is convertible from TextFile.
  • A resolved source is only added if get_converter() finds a converter for it. Invalid resolved types (e.g. clashing classifiers) and ones needing no conversion are skipped.

  • The extras modules of generically classifiable formats (e.g. archives) are imported first, so the result doesn't depend on which extras happen to be imported already.

  • Fixed WithClassifiers.register_converter checking for duplicate generic converters in a converters dict inherited from a base class (e.g. FsObject's, which can hold unclassified archive types), instead of the unclassified type's dict that the converter is stored in

Behaviour change: every format's convertible_from() now includes archives of itself (Zip[X], Tar[X], TarGzip[X]).

Tests

  • New test_convertible_from_wildcards.py for the resolved cases, and checks that there are no wildcard members.
  • Existing exact-union tests now check the non-generic members exactly, and that the archive members are present. Generic converters registered by other test modules made exact unions depend on test order.

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.31373% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fileformats/core/fileset.py 85.71% 3 Missing and 4 partials ⚠️
fileformats/core/mixin.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tclose
tclose merged commit 68ce56d into main Oct 19, 2026
19 checks passed
@tclose
tclose deleted the resolve-convertible-from-wildcards branch October 19, 2026 07:41
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