Skip to content

fix: add missing type annotations, warn on ncdf deprecation - #32

Open
petercorke wants to merge 5 commits into
mainfrom
fix/annotations-and-deprecation-warnings
Open

fix: add missing type annotations, warn on ncdf deprecation#32
petercorke wants to merge 5 commits into
mainfrom
fix/annotations-and-deprecation-warnings

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Type annotations (finding 6)

  • Histogram.plot(): full signature was completely unannotated. Added types to every parameter and the return type. Kept the type= parameter name as-is despite shadowing the builtin — it's public API (hist.plot(type="pdf")), renaming is a breaking change out of scope here. Left it typed as plain str rather than Literal — its docstring's listed values don't match what the method actually accepts (logged as its own tech-debt.md entry, found while doing this).
  • ImageRegionFeatures.py: both __str__/__repr__ pairs → str
  • Sources.py: _open_reader()Any (conditionally-imported ROS reader type behind an optional dependency, matching the existing pattern used elsewhere in the file)

Deprecation warnings (finding 7, corrected from the original review) — the original review's ImageCore.py A-property version-drift claim didn't reproduce (both sides already say 2.0.0). The real gap: ImageWholeFeaturesMixin.ncdf (Image.ncdf) and Histogram.ncdf both had a .. deprecated:: 2.0.0 docstring note but neither ever called warnings.warn, unlike every other deprecated method in the codebase. Added the standard warning to both, with messages matching what each actually delegates to — also fixed Histogram.ncdf's docstring, which incorrectly said "use hist().cdf" despite self already being the Histogram instance.

Test plan

  • Added a regression test for the new Histogram.ncdf warning, updated the existing Image.ncdf test to also assert the warning
  • Verified genuinely: reverted just the two warnings.warn calls (source only, kept tests), confirmed both fail with "DeprecationWarning not triggered", restored the fix, confirmed both pass
  • Full suite: 817 passed (816 + 1 net new test), 15 skipped, no regressions

Found while adding type annotations to plot() -- the docstring lists
'frequency'/'cdf'/'ncdf' as the accepted type= values, but the actual
dispatch also accepts 'pdf'/'probability'/'cf'/'cumulative'/'normalized'
and does not handle 'ncdf' at all. Left type annotated as plain str
rather than Literal for this reason -- reconciling docstring vs
behavior is a separate decision, out of scope for an annotations-only
pass.
Type annotations (finding 6):
- Histogram.plot(): full signature was completely unannotated. Added
  types to every parameter and the return type. Deliberately kept the
  type= parameter name as-is despite shadowing the builtin -- it's a
  public keyword argument (hist.plot(type="pdf")), renaming it is a
  breaking change out of scope here. Left it typed as plain str rather
  than Literal (see tech-debt.md entry added alongside this commit --
  the docstring's listed values don't match what the method actually
  accepts).
- ImageRegionFeatures.py: __str__/__repr__ (x2 each) -> str
- Sources.py: _open_reader() -> Any (conditionally-imported ROS reader
  type behind an optional dependency; Any matches the existing pattern
  used elsewhere in this file for the same reason)

Deprecation warnings (finding 7, corrected from the original review --
the ImageCore.py "A" property version-drift claim didn't reproduce,
both sides already said 2.0.0):
- ImageWholeFeaturesMixin.ncdf (Image.ncdf) and Histogram.ncdf both had
  a .. deprecated:: 2.0.0 docstring note but neither ever called
  warnings.warn, unlike every other deprecated method in the codebase.
  Added the standard warning to both, with messages matching what each
  actually delegates to (hist().cdf for the Image-level property,
  plain .cdf for the Histogram-level one -- also fixed the second
  property's docstring, which incorrectly said "hist().cdf" despite
  self already being the Histogram instance).

Added a regression test for the new Histogram.ncdf warning and updated
the existing (already-passing) Image.ncdf test to also assert the
warning. Verified genuinely: reverted just the two warnings.warn calls
(via git stash on the source file only, keeping the tests), confirmed
both fail with "DeprecationWarning not triggered", restored the fix,
confirmed both pass.

Full suite: 817 passed (816 + 1 net new test), 15 skipped, no
regressions.
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
ErrorProne 1 high

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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