Skip to content

Convert FileFormatModel from ABC to typing.Protocol#3692

Open
nssalian wants to merge 1 commit into
apache:mainfrom
nssalian:file-format-model-protocol
Open

Convert FileFormatModel from ABC to typing.Protocol#3692
nssalian wants to merge 1 commit into
apache:mainfrom
nssalian:file-format-model-protocol

Conversation

@nssalian

@nssalian nssalian commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Closes #3100

Rationale for this change

FileFormatModel had only abstract methods (no shared implementation), so an ABC was heavier than needed. This PR converts it to typing.Protocol, which is the more Pythonic pattern for a pure interface. FileFormatWriter remains an ABC since it has shared __enter__/__exit__/result implementations that inheritance carries for free. FileFormatFactory is unchanged - it matches the existing AuthManagerFactory pattern.

Changes

New format implementations can now conform structurally without inheriting from FileFormatModel. Net: 2 ABCs → 1 ABC + 1 Protocol. No signature change for existing callers; ParquetFormatModel(FileFormatModel) inheritance is retained (Protocol supports explicit conformance).

Are these changes tested?

Yes. tests/io/test_fileformat.py adds two tests using a shared _StructuralModel helper:

  • test_file_format_model_is_protocol - a structurally-conforming class (no inheritance) passes isinstance() against FileFormatModel.
  • test_structural_model_works_with_factory - a structurally-conforming class can be registered and retrieved via FileFormatFactory end-to-end.

Are there any user-facing changes?

No. Default behavior is unchanged.

@nssalian
nssalian marked this pull request as ready for review July 23, 2026 22:40
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.

File Format API for PyIceberg

1 participant