Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing visibility for ExporterConfig #232

Merged
merged 1 commit into from
Dec 31, 2024
Merged

Fix typing visibility for ExporterConfig #232

merged 1 commit into from
Dec 31, 2024

Conversation

dyastremsky
Copy link
Contributor

ExporterConfig was previously functioning as a dataclass without being one. In its init, all the types were set to None, even though the functions calling the config expected them to actually be set to a type. In other words, the type hint listed None but it was never actually supposed to be None. This resulted in Pylance errors everywhere we used this class's data objects and unclear visibility into the types of each object. This slowed development and was likely to lead to failures, albeit it made testing a bit easier (only the necessary data had to be set).

This pull request changes ExporterConfig to be a datatype and cleans up the type hints. It also adds a test util function to create a sample exporter config to keep the tests concise, create a single source of truth for changing the ExporterConfig in unit testing. That should make the unit testing more flexible and faster to update if this class changes in the future.

config.stats = stats.stats_dict
config.metrics = stats.metrics
config.args = args
assert isinstance(stats.metrics, Metrics)
Copy link
Contributor Author

@dyastremsky dyastremsky Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These asserts are necessary because the current architecture means that stats.metrics can be Metrics or TelemetryMetrics. It is beyond the scope of this PR to separate the two, but we do need asserts like this to check the correct type is used and to not result in type checking failures. It was previously opaque that we were using two types in the exporter config.

We could always tackle it in a future cleanup effort if it causes issues, but making the typing transparent should help.

@dyastremsky dyastremsky merged commit 9e2035b into main Dec 31, 2024
6 of 7 checks passed
@dyastremsky dyastremsky deleted the dyas-cleanup branch December 31, 2024 17: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.

2 participants