Skip to content

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

Closed
ovodela wants to merge 1 commit into
capitalone:devfrom
ovodela:refactor/remove-unnecessary-cast-reports
Closed

refactor: replace cast() with isinstance assertions in reports#1218
ovodela wants to merge 1 commit into
capitalone:devfrom
ovodela:refactor/remove-unnecessary-cast-reports

Conversation

@ovodela

@ovodela ovodela commented Aug 31, 2026

Copy link
Copy Markdown

Summary

  • Replaces all 4 cast() calls in dataprofiler/reports/graphs.py with assert isinstance() or assert is not None checks
  • Provides both static type safety (mypy narrowing) and runtime validation instead of unchecked casts
  • Removes unused Union and cast imports from typing
  • The cast(F, new_f) in utils.py is intentionally retained -- it handles a fundamental typing limitation with decorator return types that cannot be expressed with isinstance

Changes

Location Before After
Line 77 cast(list[Union[str, int]], column_names) assert column_names is not None
Line 100 cast(ColumnPrimitiveTypeProfileCompiler, ...) assert isinstance(data_compiler, ...)
Line 130 Same cast Same assert
Line 269 cast(Figure, ax.figure) assert ax.figure is not None

Test plan

  • All existing test_graphs.py tests pass (16 tests)
  • mypy reports no new type errors
  • No behavioral changes -- assertions are satisfied on all existing code paths

Addresses #720

Replace cast() calls with assert isinstance() checks where the type
narrowing serves to access subclass attributes. This provides both
static type safety and runtime validation instead of unchecked casts.

The cast(F, new_f) in utils.py is retained as it handles a fundamental
typing limitation with decorator return types that cannot be expressed
with isinstance.

Addresses capitalone#720
@ovodela
ovodela requested a review from a team as a code owner August 31, 2026 22:14
@CLAassistant

CLAassistant commented Aug 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ovodela ovodela closed this Sep 9, 2026
@ovodela

ovodela commented Sep 9, 2026

Copy link
Copy Markdown
Author

Closing this PR — re-submitting through the Capital One Spork contribution pipeline (via capitalone-contributions fork) for proper compliance. Same changes will be in the new PR.

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