You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
List lazy public names in dir() from one table per module - #7155
Standardized how public names are loaded on demand across the package. Available names are consistently discoverable through module listings, while unavailable names continue to raise AttributeError.
Existing lazy exports remain accessible, including compatibility names used by parser modules.
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The PR adds shared hooks for lazy module exports and applies them across package, CLI, parser, reference, type, and utility modules. It also adds public-API checks for lazy names, directory listings, and missing-name errors.
Parser modules use the shared hooks for lazy exports. The architecture-boundary allowlist names the dataclass and msgspec loader functions; the typed-dict entry remains keyed by __getattr__.
This change makes dir() for modules with lazy exports list each public name once, using the same table as attribute lookup. No merge-blocking risk was identified.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
[#7152] The shared module_hooks__dir__ lists each name once. reference.py__all__ returns public non-lazy names followed by lazy exports, so a name that is stored in globals is not listed twi…
Confirm, from the diff against merge base d19bc4f, that the missing-attribute messages of datamodel_code_generator, util, types, parser.avro, parser.asyncapi, parser.base, parser.jsonschema, `r…
Passed checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "List lazy public names in dir() from one table per module" matches the main change. The raw summary shows a new shared module_hooks helper in _lazy_exports.py that answers __dir__ fro…
Out of Scope Changes check
The changes support the two linked issues. The new _lazy_exports.py helper provides the shared table, __getattr__, and __dir__ used by each affected module. The per-module edits in __init__.py…
Full details: Title check
Explanation
The title "List lazy public names in dir() from one table per module" matches the main change. The raw summary shows a new shared module_hooks helper in _lazy_exports.py that answers __dir__ from the same table used by __getattr__, and that is applied across the affected modules. The linked objectives (#7152 and #7154) target listing each lazy public name once in dir(), which the title describes. The title is specific and concise, and it names the primary change.
Full details: Out of Scope Changes check
Explanation
The changes support the two linked issues. The new _lazy_exports.py helper provides the shared table, __getattr__, and __dir__ used by each affected module. The per-module edits in __init__.py, __main__.py, parser/*.py, reference.py, types.py, and util.py replace the old hand-written hooks with that helper. The scripts/check_architecture_boundaries.py allowlist keys were updated to match the renamed parser/base.py hooks. This is a supporting change. The tests in tests/main/test_public_api_signature_baseline.py and the .refs file cover the new dir and __all__ behavior. The docs migration TOML files document the change. No unrelated functional change appears in the summary.
Full details: Linked Issues check
Explanation
[#7152] The shared module_hooks__dir__ lists each name once. reference.py__all__ returns public non-lazy names followed by lazy exports, so a name that is stored in globals is not listed twice. This addresses the duplicate behavior. [#7154] The package root, types, util, parser.avro, parser.asyncapi, parser.base, parser.jsonschema, and __main__ now answer dir() from the same table as __getattr__. _types is not changed. The objective requires each module's AttributeError text to remain unchanged. The summary says the util module's explicit missing-attribute error was removed and that module_hooks has a missing_message option (standard or name). The summary does not show the old and new message text for util and the package root. The expected baseline files are ignored and were not inspected. Compliance with the message requirement cannot be confirmed from the summary.
Resolution
Confirm, from the diff against merge base d19bc4f, that the missing-attribute messages of datamodel_code_generator, util, types, parser.avro, parser.asyncapi, parser.base, parser.jsonschema, reference, and __main__ match their pre-change text. Specifically, check the util module and the package root, where the old custom error was replaced by the shared hook. Also confirm that the missing_message value passed for each module matches the old message format.
Finishing Touches
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.
Reviewing files that changed from the base of the PR and between d19bc4f and c88090a.
Files ignored due to path filters: 12
docs/data/migration/unreleased/boundary-report-lazy-export-lines.toml is excluded by none and included by none
docs/data/migration/unreleased/lazy-public-names-in-dir.toml is excluded by none and included by none
tests/data/expected/architecture_boundaries/cli.txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.__main__].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.parser.asyncapi].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.parser.avro].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.parser.base].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.parser.jsonschema].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.reference].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.types].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator.util].txt is excluded by !tests/data/**/*.txt and included by none
tests/data/expected/main/public_api_signature_baseline/lazy_public_names_are_listed_once_by_dir[datamodel_code_generator].txt is excluded by !tests/data/**/*.txt and included by none
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
⚠️53 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
Reasoning: The PR moves every module-level lazy getattr onto a shared internal helper that also supplies dir. Missing-name error messages and caching stay the same in every module: the root package and reference still cache, and avro, base and jsonschema still raise with the name alone. The behaviour diff gate has only both-fail cells, so generated code and default output do not change. Two Python API changes reach released behaviour. First, the diff removes the plain imports of create_module_getattr in types.py and parser/asyncapi.py, so the function can no longer be imported from those modules or picked up by star imports of them. It remains available from util. Second, dir() on the root package, types, util, parser.avro, parser.asyncapi, parser.base, parser.jsonschema and main now lists the lazily exported names, so introspection through inspect.getmembers, help or completion now triggers the imports behind those names. The fix that stops reference listing a name twice in dir() and all is a correction to the same introspection behaviour. The other changes are internal or test-only: renaming the private table, updating the architecture-boundary allowlist, and the stored test outputs.
Content for Release Notes
API/CLI Changes
Removed create_module_getattr from datamodel_code_generator.types and datamodel_code_generator.parser.asyncapi - Both modules used to import create_module_getattr from datamodel_code_generator.util for their old lazy __getattr__ hooks. That meant from datamodel_code_generator.types import create_module_getattr, the same import from datamodel_code_generator.parser.asyncapi, and star imports of either module all gave you that name. Those imports are gone because the modules now use the internal _lazy_exports helper, so code that reached the function through either module gets ImportError or AttributeError. Import it from datamodel_code_generator.util, where it is still available. (List lazy public names in dir() from one table per module #7155)
Module dir() now lists lazily exported names - The package root, types, util, parser.avro, parser.asyncapi, parser.base, parser.jsonschema and __main__ now define __dir__, so dir() now includes lazy names such as StrictTypes, BaseModel, SafeLoader, dataclass_model, msgspec_model, TypedDictModel, Config, generate_dynamic_models and load_pyproject_config, which it used to leave out. Anything that walks dir() and reads each attribute, such as inspect.getmembers(), help() and REPL completion, now imports the modules behind those names. For example, it loads the dataclass and msgspec model modules for parser.base and the protobuf and XML Schema parsers for parser.asyncapi. Also, once a resolver name in datamodel_code_generator.reference has been read, dir() and __all__ now list it once instead of twice. (List lazy public names in dir() from one table per module #7155)
This analysis was produced by the release draft workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #7152
Fixes: #7154
Summary by CodeRabbit
AttributeError.