Skip to content

Improve type hints in API, core, and config helpers - #196

Open
hippi345 wants to merge 1 commit into
epic-open-source:mainfrom
hippi345:cursor/reduce-typing-warnings-eb34
Open

hippi345 wants to merge 1 commit into
epic-open-source:mainfrom
hippi345:cursor/reduce-typing-warnings-eb34

Conversation

@hippi345

Copy link
Copy Markdown

Overview

Part of #79

Description of changes

This addresses a bounded slice of mypy findings (about 50 errors fixed; about 402 remain repo-wide), so it is meant as a first step rather than closing the issue.

  • Correct implicit Optional annotations (run_startup, reports, loader hooks, HTML templates, etc.).
  • Replace mistaken builtin any with typing.Any in cohort/filter/plot signatures.
  • Fix api/__init__.py module references for __all__ construction.
  • Align init_logger return type with behavior (logging.Logger).
  • Fix TelemetryConfig empty-list initialization (ports vs files).
  • Tighten DiskCachedFunction.return_type typing; loader pipeline asserts for optional hooks.
  • Add [tool.mypy] overrides for common untyped third-party modules; add pandas-stubs and types-PyYAML to [dev].
  • News fragment: changelog/79.misc.rst.

Verified locally: pre-commit run --all-files passes; coverage run -m pytest gives 1550 passed, 1 skipped, 90% coverage; python -m build and twine check pass.

Author Checklist

  • Linting passes; run early with pre-commit hook.
  • Tests added for new code and issue being fixed.
  • Added type annotations and full numpy-style docstrings for new methods.
  • For breaking API changes, added .. versionchanged:: NEXT_VERSION_PLACEHOLDER directive to affected docstrings.
  • Draft your news fragment in new changelog/ISSUE.TYPE.rst files; see changelog/README.md.

…fig helpers

Fix implicit Optional annotations, builtin any misuse, and several loader
and decorator typing issues. Add mypy config overrides for untyped third-party
modules and pandas-stubs/types-PyYAML dev dependencies.
@hippi345
hippi345 requested a review from a team as a code owner October 30, 2026 15:13
@CLAassistant

CLAassistant commented Oct 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment on lines +270 to +272
if dtype is None:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These lines aren't needed: return dtype right below already returns None when dtype is None. Please remove them.

Comment on lines +68 to +69
cast("str | Path", config_path),
output_path=cast("str | Path | None", output_path),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

None is valid here (ConfigProvider falls back to ./data), so please don't cast. Instead, add | None to config_config and output_path in ConfigProvider (plus _load_config_config, _resolve_other_paths and set_output, which already handle None), and keep this call as it is on main.

Comment thread setup.cfg
pytest>=5.1.1
traitlets>=5.1.1
pygments>=2.4.1
pandas-stubs>=2.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This installs the pandas 3 stubs while we require pandas<3. Please pin it to match: pandas-stubs>=2.1,<3.

hierarchies: Optional[list["CohortHierarchy"]] = None,
hierarchy_combinations: Optional[dict[tuple[str], "pd.DataFrame"]] = None,
hierarchies: Optional[list[CohortHierarchy]] = None,
hierarchy_combinations: Optional[dict[tuple[str], pd.DataFrame]] = None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tuple[str] is a 1-tuple; the keys can be any length. Could we use tuple[str, ...]?

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.

3 participants