Skip to content

Add type annotations with ty - #129

Merged
GeorgePearse merged 11 commits into
masterfrom
add-type-annotations-with-zuban
Oct 25, 2025
Merged

Add type annotations with ty#129
GeorgePearse merged 11 commits into
masterfrom
add-type-annotations-with-zuban

Conversation

@GeorgePearse

Copy link
Copy Markdown
Owner

No description provided.

…tion

- Add zuban>=0.1.0 as dev dependency in pyproject.toml
- Configure mypy (used by zuban) to ignore all files initially
- Allow untyped definitions to start gradual type annotation adoption
- This sets up the foundation for incrementally adding type annotations
  to modules one at a time, with zuban validating as we go
- Configuration enables: allow_untyped_defs, allow_incomplete_defs,
  ignore_missing_imports, allow_untyped_globals
- Files will be enabled in [mypy] section as they receive type annotations
- Document the gradual type annotation adoption strategy
- Explain how to enable modules one at a time for type checking
- Provide type annotation guidelines and examples
- Show how to increase strictness as coverage improves
- Include common patterns and resources for type annotations
…elines

- Create scratch_files/ directory for agent-generated documentation
- Update AGENTS.md with clear guidance that agents should write documentation
  to scratch_files/ instead of the repository root
- Keep root directory clean with only essential docs (README.md, AGENTS.md, etc)
- Allow agents to freely create capitalized markdown files in scratch_files/
- Include examples of appropriate documentation locations
Move the following documentation files to scratch_files/ to keep the
repository root clean with only essential documentation:
- PUBLISHING.md → scratch_files/PUBLISHING.md
- PYPI_SETUP.md → scratch_files/PYPI_SETUP.md
- TYPE_ANNOTATIONS.md → scratch_files/TYPE_ANNOTATIONS.md

Keep in root: README.md, AGENTS.md, CLAUDE.md (essential project docs)
Agent-generated and operational docs now live in scratch_files/
Resolve conflicts and apply documentation guidelines:
- Combine dev dependencies from both branches (zuban + testing utils)
- Remove duplicate TYPE_ANNOTATIONS.md from root (keep in scratch_files/)
- Move TESTING.md and TESTING_PLAN.md to scratch_files/ per new guidelines
- Include testing infrastructure from master:
  - New comprehensive Kalman filter tests
  - Testing utilities module for shared test helpers
  - Improved test coverage workflow
  - pytest configuration with conftest
- Fix batch_filter to handle None Bs parameter when us is provided
- Fix MMAE __init__ to use default arrays instead of None for x and P
- Add type narrowing assertion in plot_covariance_ellipse for ellipse parameter
- Initialize fx, hx, and H attributes in ExtendedKalmanFilter class

These changes resolve type checking errors identified by zuban type checker.
- Replace zuban with ty type checker in pyproject.toml
- Update mypy configuration section to ty configuration with proper src/env settings
- Add comprehensive type annotations to achieve full ty type compliance
  - gh_filter.py: Add type hints and k parameter validation for order 2 filters
  - hinfinity_filter.py: Add SaverProtocol and proper type annotations for batch_filter
  - fixed_lag_smoother.py: Add type hints and N parameter validation for smooth()
  - kalman_filter.py: Fix Bs parameter handling and F array conversion in predict()

All 21 initial type diagnostics now resolved. ty check reports: "All checks passed!"
…instead of atleast_2d

Replace the problematic 4-line atleast_2d() conversion that broke broadcasting
when scalar F=1 was converted to shape (1,1) matrix. The original behavior using
0-D arrays allows NumPy dot products to correctly broadcast scalars across any
dimensionality of x.

Changed from:
  if isscalar(F): F = np.atleast_2d(np.asarray(F, dtype=float))
  else: F = np.asarray(F)

To:
  F = np.asarray(F, dtype=float)

This single-line approach:
- Preserves 0-D scalar arrays for correct broadcasting
- Maintains type compliance (F is ndarray)
- Simplifies code (1 line vs 4 lines)
- Fixes regression in test_functions (scalar F with multi-dim x)

Fixes #P0-scalar-F-regression
Remove GitHub fork metadata to present this as an independent project:
- Remove 'fork' language from README, docs/index.md, and AGENTS.md
- Remove 'About This Fork' section from docs/index.md
- Remove 'Original Project' URL from pyproject.toml
- Change AGENTS.md language from 'fork' to 'independent project'
- Delete import-upstream-*.py scripts

Preserve educational/historical context:
- Keep references to original FilterPy library in docs
- Keep book references (Kalman and Bayesian Filters in Python)
- Keep links to original repository in resource sections
- Maintain critical guidance in AGENTS.md about not submitting PRs upstream
Remove unnecessary return statements from test functions:
- test_enkf.py::test_1d_const_vel: Remove 'return f'
- test_mmae.py::test_MMAE2: Remove 'return bank'
- test_ukf.py::test_linear_rts: Remove 'return ukf'

Test functions should return None, not test objects. This resolves all 4
PytestReturnNotNoneWarning warnings. All 231 tests now pass cleanly with
only the hypothesis pytest plugin warning remaining (unrelated).
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  bayesian_filters/gh
  gh_filter.py 122, 125, 128-129, 172-184
  bayesian_filters/hinfinity
  hinfinity_filter.py
  bayesian_filters/kalman
  EKF.py
  fixed_lag_smoother.py 169
  kalman_filter.py 1554, 1747-1748, 1751
  mmae.py 127-130
  bayesian_filters/stats
  stats.py 1090-1097
Project Total  

This report was generated by python-coverage-comment-action

@GeorgePearse GeorgePearse changed the title Add type annotations with zuban Add type annotations with ty Oct 25, 2025
@GeorgePearse
GeorgePearse merged commit 95d769e into master Oct 25, 2025
11 checks passed
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.

1 participant