Skip to content

Return the dataclass Metadata from the C reader - #498

Open
oschwald wants to merge 1 commit into
mainfrom
greg/c-extension-metadata-dataclass
Open

oschwald wants to merge 1 commit into
mainfrom
greg/c-extension-metadata-dataclass

Conversation

@oschwald

@oschwald oschwald commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

The C extension's metadata() now returns maxminddb.reader.Metadata, the same dataclass the pure Python reader returns. Metadata from both readers is the same type, compares equal with ==, and works with repr() and dataclasses.asdict(). maxminddb.extension.Metadata stays as an alias of that class.

User-visible changes compared with 3.2.0, all listed in HISTORY.rst:

  • type(reader.metadata()) is maxminddb.reader.Metadata in both modes.
  • hash() raises TypeError, as it already did for the pure Python class.
  • The constructor takes keyword arguments only. A missing or unknown argument raises TypeError, and assignment raises dataclasses.FrozenInstanceError.

The extension builds the keyword arguments with one Py_BuildValue call and calls the class after releasing the read lock, as before. Tests pass with the extension forced, with it disabled, and on free-threaded 3.14t.

Related: #468.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Metadata from the C-extension and pure-Python readers now uses the same Metadata type. Metadata values from both readers compare equally and support repr() and dataclasses.asdict().
    • Metadata objects are unhashable and immutable; attempts to change their attributes raise FrozenInstanceError.
    • The metadata class documents its size properties and keyword-only constructor.
  • Documentation
    • Updated the 3.3.0 changelog to describe the shared metadata behavior and class properties.

The C extension's metadata() now returns maxminddb.reader.Metadata,
the dataclass that the pure Python reader returns. Metadata from both
readers is now the same type, compares equal, and works with repr()
and dataclasses.asdict(). maxminddb.extension.Metadata stays as an
alias of this class.

As with the pure Python class, hash() raises TypeError, and the
constructor takes only keyword arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 19:45

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. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: acef382f-1a8c-4286-86f1-ddcf5272bde2
Commits

Reviewing files that changed from the base of the PR and between 7b5e44b and 5caced9.

Files selected for processing: 4
  • HISTORY.rst
  • extension/maxminddb.c
  • maxminddb/extension.pyi
  • tests/reader_test.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The C extension now imports Metadata from maxminddb.reader and uses it to create metadata results. The extension stub, tests, and changelog now describe the shared class and its behavior.

Changes: Shared Metadata Type

Layer / File(s) Summary
Extension integration
extension/maxminddb.c
The extension imports Metadata from maxminddb.reader and constructs metadata with keyword arguments. It removes the extension-defined type and its constructor, fields, and properties.
Public contract and validation
maxminddb/extension.pyi, tests/reader_test.py, HISTORY.rst
The stub re-exports the reader’s Metadata. Tests check the shared class, equality, representation, dataclass values, and unhashability. The changelog records the shared class and its documented behavior.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: horgh

Merge Risk: Minimal · up to 5cace

The shared metadata change has no identified merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: the C reader now returns the dataclass Metadata.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the fields with care,
One Metadata class is now shared there.
The readers match in form and name,
Their frozen values play the same.
I twitch my nose and hop away.

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants