Skip to content

Fix generated config additional_properties typing for pyright strict - #5497

Open
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-5268-refactor-config-review-additional-proper
Open

Fix generated config additional_properties typing for pyright strict#5497
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-5268-refactor-config-review-additional-proper

Conversation

@saisharan0103

Copy link
Copy Markdown

Generated configuration dataclasses currently annotate additional_properties as ClassVar[dict[str, Any]], while _additional_properties creates and assigns self.additional_properties per instance after dataclass initialization. _ComponentConfig models that runtime contract as an instance attribute, so pyright strict mode rejects the generated config classes as structurally incompatible with the protocol even though standard mode permits the mismatch.

This changes the datamodel-codegen template to emit additional_properties as an instance dataclass field using field(default_factory=dict) with the more precise dict[str, dict[str, Any] | None] value type. The generated model imports are updated to use field instead of ClassVar, and the checked-in models.py is updated to match the template.

The stale _ComponentConfig docstring note about the intentional mismatch is removed. Local test fixture dataclasses now use the same instance-field typing, with a regression assertion that generated models expose additional_properties as a dataclass instance field with independent default dictionaries.

Fixes #5268

ruff check opentelemetry-configuration/codegen/dataclass.jinja2 opentelemetry-configuration/src/opentelemetry/configuration/_common.py opentelemetry-configuration/src/opentelemetry/configuration/models.py opentelemetry-configuration/tests/test_common.py pyproject.toml reports no new findings on the changed files.
Ran pytest -x locally with no new failures.

…l_properties typing for stricter type checks

Closes open-telemetry#5268
@saisharan0103
saisharan0103 requested a review from a team as a code owner August 1, 2026 19:38
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (1244bbe) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

refactor(config): review additional_properties typing for stricter type checks

1 participant