Skip to content

Address general type issues#1922

Merged
victorlin merged 6 commits intomasterfrom
victorlin/types
Feb 20, 2026
Merged

Address general type issues#1922
victorlin merged 6 commits intomasterfrom
victorlin/types

Conversation

@victorlin
Copy link
Copy Markdown
Member

@victorlin victorlin commented Oct 27, 2025

Description of proposed changes

Enable reportGeneralTypeIssues and address existing issues. Commits roughly ordered from simplest to most complex.

Related issue(s)

Follow-up to:

augur/pyrightconfig.json

Lines 14 to 15 in e19f2c2

// TODO: go through these exceptions and determine if they should be kept or
// removed and violations addressed.

#1917 (review) suggested adding type hints, and I figured this PR would make the hints more useful.

Checklist

  • Automated checks pass
  • Check if you need to add a changelog message
  • Check if you need to add tests
  • Check if you need to update docs

@victorlin victorlin self-assigned this Oct 27, 2025
@victorlin
Copy link
Copy Markdown
Member Author

This introduced new Mypy errors:

augur/validate_export.py:55: error: Need type annotation for "seen"  [var-annotated]
augur/validate_export.py:204: error: Need type annotation for "seen"  [var-annotated]
…
augur/filter/subsample.py:353: error: "str" not callable  [operator]
augur/filter/subsample.py:353: error: "bytes" not callable  [operator]
augur/filter/subsample.py:353: error: "date" not callable  [operator]
augur/filter/subsample.py:353: error: "datetime" not callable  [operator]
augur/filter/subsample.py:353: error: "timedelta" not callable  [operator]
augur/filter/subsample.py:353: error: "datetime64[Union[date, int]]" not callable  [operator]
augur/filter/subsample.py:353: error: "timedelta64[Union[timedelta, int]]" not callable  [operator]
augur/filter/subsample.py:353: error: "bool" not callable  [operator]
augur/filter/subsample.py:353: error: "int" not callable  [operator]
augur/filter/subsample.py:353: error: "float" not callable  [operator]
augur/filter/subsample.py:353: error: "Timestamp" not callable  [operator]
augur/filter/subsample.py:353: error: "Timedelta" not callable  [operator]
augur/filter/subsample.py:353: error: "complex" not callable  [operator]
augur/filter/subsample.py:353: error: "integer[Any]" not callable  [operator]
augur/filter/subsample.py:353: error: "floating[Any]" not callable  [operator]
augur/filter/subsample.py:353: error: "complexfloating[Any, Any]" not callable  [operator]
Found 18 errors in 2 files (checked 82 source files)

The first 2 aren't necessary (Pyright infers that seen is ~TreeAttrs) and all the rest are false positives (Pyright infers that row is _PandasNamedTuple, not any of the types reported by Mypy).

For now, I'll plan to add # type: ignore to appease Mypy. Long-term, with a more comprehensive Pyright config, it might be good to ditch Mypy to align with nextstrain/cli@4a4e500.

Comment thread augur/filter/subsample.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.46%. Comparing base (b4f4657) to head (57c36c4).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
augur/dates/ambiguous_date.py 0.00% 1 Missing ⚠️
augur/validate_export.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1922      +/-   ##
==========================================
+ Coverage   74.44%   74.46%   +0.02%     
==========================================
  Files          82       82              
  Lines        9089     9098       +9     
  Branches     1853     1853              
==========================================
+ Hits         6766     6775       +9     
  Misses       2020     2020              
  Partials      303      303              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@victorlin victorlin mentioned this pull request Oct 27, 2025
4 tasks
From doc¹:

    Generate or suppress diagnostics for general type inconsistencies,
    unsupported operations, argument/parameter mismatches, etc. This covers
    all of the basic type-checking rules not covered by other rules. It does
    not include syntax errors.

Existing issues will be addressed in subsequent commits.

¹ https://microsoft.github.io/pyright/#/configuration?id=type-check-rule-overrides
Raising a string literal instead of a proper exception is not allowed by
Pyright.
This allows Pyright to know the dict structure for type checking.
This removes duplicated lambdas and the need for type annotation on the
'seen' variable.
@victorlin victorlin force-pushed the victorlin/types branch 2 times, most recently from 5a213dc to 135fd7b Compare February 18, 2026 23:09
There was a type error with the previous code:

    subsample.py:353:12 - error: Invalid conditional operand of type "Series[bool]"
        Method __bool__ for type "Series[bool]" returns type "NoReturn" rather than "bool" (reportGeneralTypeIssues)

This is because iterrows() yields Series, and Series.__getitem__ returns
Series[Any] | Any (scalar). Pyright sees row[…] as that type, which
means the outcome of the comparison operator is Series[bool] | bool.
Series[bool] cannot be used as-is for the if condition.

This could be addressed by casting 'int(…) < int(…)', but switching to a
loop targeted on specific columns with itertuples() seems more
appropriate as it addresses the type error and is more efficient.¹

¹ https://stackoverflow.com/a/70227993
Errors for augur/validate_export.py:

    Need type annotation for "seen"  [var-annotated]

This is unnecessary – Pyright correctly infers that seen is ~TreeAttrs.
@victorlin victorlin merged commit 0d91730 into master Feb 20, 2026
32 checks passed
@victorlin victorlin deleted the victorlin/types branch February 20, 2026 02:00
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