Visitar URL original
Pin public module exports by koxudaxi · Pull Request #3364 · datamodel-code-generator/datamodel-code-generator · GitHub
Skip to content

Pin public module exports - #3364

Merged
Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
test/module-export-baseline
Jun 13, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
mainfrom
test/module-export-baseline

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a parametrized test that validates public API exports across datamodel_code_generator submodules. The test dynamically imports each module, verifies its __all__ contents match a hardcoded baseline, and confirms no duplicate exports and that all exported names are accessible.

Changes

Public API Signature Baseline Test

Layer / File(s) Summary
Public API export baseline and validation test
tests/main/test_public_api_signature_baseline.py
Adds importlib import, defines _PUBLIC_MODULE_EXPORTS baseline mapping expected exports per submodule, and implements parametrized test test_public_module_all_exports_match_baseline that validates each module's __all__ matches baseline exactly, contains no duplicates, and all names are importable as module attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A baseline for exports, precise and clear,
Each module's __all__ must now appear,
No hidden names, no duplicates hide,
The public API, with nothing denied!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'Pin public module exports' clearly and concisely summarizes the main change: establishing a baseline to lock down the public module exports.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/module-export-baseline

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

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

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
tests/main/test_public_api_signature_baseline.py (1)

631-645: 💤 Low value

Well-structured parametrized test with clear assertions.

The test logic is sound:

  • Dynamically imports each module and retrieves its __all__
  • Detects duplicates via set length comparison
  • Validates baseline match with clear diff output
  • Verifies importability (correctly triggers __getattr__ for lazy imports per context snippet)
💡 Optional: Consider reordering assertions for faster failure on fundamental errors

Moving the importability check before baseline comparison would catch fundamental errors (broken imports) before diffing:

 `@pytest.mark.parametrize`(("module_name", "expected_exports"), _PUBLIC_MODULE_EXPORTS.items())
 def test_public_module_all_exports_match_baseline(module_name: str, expected_exports: frozenset[str]) -> None:
     """Pin focused public module export surfaces used by compatibility shims."""
     module = importlib.import_module(module_name)
     module_exports = list(module.__all__)
     actual_exports = set(module_exports)
     missing_exports = [name for name in module_exports if not hasattr(module, name)]

     assert len(module_exports) == len(actual_exports), f"{module_name}.__all__ contains duplicate names"
+    assert missing_exports == [], f"{module_name}.__all__ contains non-importable names: {missing_exports}"
     assert actual_exports == expected_exports, (
         f"{module_name}.__all__ changed:\n"
         f"  removed: {sorted(expected_exports - actual_exports)}\n"
         f"  added: {sorted(actual_exports - expected_exports)}"
     )
-    assert missing_exports == [], f"{module_name}.__all__ contains non-importable names: {missing_exports}"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/main/test_public_api_signature_baseline.py` around lines 631 - 645, In
test_public_module_all_exports_match_baseline, move the importability assertion
that checks missing_exports (computed from module_exports and hasattr) to run
before the duplicate and baseline equality assertions so broken or
non-importable names fail fast; specifically, after computing module_exports,
actual_exports and missing_exports, assert missing_exports == [] first, then
proceed to the existing duplicate check (len(module_exports) vs
len(actual_exports)) and the expected_exports equality check. This keeps the
test names/variables (module_exports, actual_exports, missing_exports) and
behavior unchanged but reorders the checks for faster failure on importability
issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/main/test_public_api_signature_baseline.py`:
- Around line 631-645: In test_public_module_all_exports_match_baseline, move
the importability assertion that checks missing_exports (computed from
module_exports and hasattr) to run before the duplicate and baseline equality
assertions so broken or non-importable names fail fast; specifically, after
computing module_exports, actual_exports and missing_exports, assert
missing_exports == [] first, then proceed to the existing duplicate check
(len(module_exports) vs len(actual_exports)) and the expected_exports equality
check. This keeps the test names/variables (module_exports, actual_exports,
missing_exports) and behavior unchanged but reorders the checks for faster
failure on importability issues.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b21bc1b-d76e-49ce-88e0-6f319b6ceaed

📥 Commits

Reviewing files that changed from the base of the PR and between 6192212 and f4bb0ad.

📒 Files selected for processing (1)
  • tests/main/test_public_api_signature_baseline.py

@koxudaxi
Koudai Aono (koxudaxi) enabled auto-merge (squash) June 12, 2026 14:21
@codspeed

codspeed Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 46.38%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 11 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ WallTime test_perf_openapi_large 3.1 s 2.1 s +51.02%
⚡ WallTime test_perf_complex_refs 2.1 s 1.4 s +48.98%
⚡ WallTime test_perf_all_options_enabled 5.7 s 3.9 s +47.85%
⚡ WallTime test_perf_deep_nested 5.5 s 3.7 s +47.52%
⚡ WallTime test_perf_multiple_files_input 3.8 s 2.6 s +46.92%
⚡ WallTime test_perf_kubernetes_style_pydantic_v2 2.8 s 1.9 s +46.44%
⚡ WallTime test_perf_duplicate_names 1,131.2 ms 772.9 ms +46.36%
⚡ WallTime test_perf_aws_style_openapi_pydantic_v2 2 s 1.4 s +45.28%
⚡ WallTime test_perf_graphql_style_pydantic_v2 839.5 ms 581.9 ms +44.28%
⚡ WallTime test_perf_large_models_pydantic_v2 3.8 s 2.7 s +43.68%
⚡ WallTime test_perf_stripe_style_pydantic_v2 2.1 s 1.5 s +42.11%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing test/module-export-baseline (f995693) with main (615c485)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@github-actions

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3364.datamodel-code-generator.pages.dev

@koxudaxi
Koudai Aono (koxudaxi) merged commit 8304cfa into main Jun 13, 2026
49 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the test/module-export-baseline branch June 13, 2026 01:05
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (615c485) to head (f995693).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3364   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          129       129           
  Lines        28826     28837   +11     
  Branches      3482      3482           
=========================================
+ Hits         28826     28837   +11     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: PR #3364 "Pin public module exports" adds explicit __all__ declarations to the package's public modules (visible in the merged state of src/datamodel_code_generator/init.py and submodules), pinning the public API surface. Defining/pinning __all__ is an additive, non-breaking change: it only affects from module import * and does not change direct imports, function signatures, default values, CLI options, generated output, templates, supported Python versions, or error handling. No public class, function, constant, enum value, or CLI option appears as removed or renamed, and the per-guardrails requirement (only report removals that appear as removed lines in the prepared diff) yields no breaking-change evidence. Note: the prepared diff files under /home/runner/work/_temp/ were inaccessible from this sandboxed session (path restrictions plus blocked network/gh/WebFetch and a single-commit clone with no parent), so this determination is based on the PR's stated scope and the merged repository state rather than a line-by-line read of the prepared diff.


This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.64.0

This PR is now available in the latest release. See the release notes for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant