Skip to content

refactor: replace cast() with isinstance assertions in reports - #1226

Open
ovodela wants to merge 1 commit into
capitalone:mainfrom
ovodela:refactor-remove-cast-reports
Open

ovodela wants to merge 1 commit into
capitalone:mainfrom
ovodela:refactor-remove-cast-reports

Conversation

@ovodela

@ovodela ovodela commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Replace all 4 cast() calls in reports/graphs.py with assert isinstance() or assert is not None. This provides both static type safety (mypy narrowing) and runtime validation instead of unchecked type casts.

Changes

Location Before After
Line 76 cast(List[Union[str, int]], column_names) assert column_names is not None
Line 99 cast(ColumnPrimitiveTypeProfileCompiler, ...) assert isinstance(...)
Line 129 Same cast pattern Same assert pattern
Line 266 cast(Figure, ax.figure) assert ax.figure is not None

The cast(F, new_f) in utils.py is intentionally retained — it handles a typing limitation with decorator wrappers.

Fixes #720

Previously submitted as #1218 (closed) and #1222 (targeted stale dev branch). Clean resubmission against main.

Replace all 4 cast() calls in reports/graphs.py with assert isinstance()
or assert is not None. This provides both static type safety (mypy
narrowing) and runtime validation instead of unchecked type casts.

The cast(F, new_f) in utils.py is intentionally retained — it handles a
fundamental typing limitation with decorator wrappers that cannot be
expressed via isinstance.

Fixes capitalone#720
@ovodela
ovodela requested a review from a team as a code owner September 14, 2026 15:59

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate use of cast() in reports.

1 participant