-
Notifications
You must be signed in to change notification settings - Fork 136
Address general type issues #1922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
Union syntax is only supported by Python ≥3.10.
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.
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
itertuples() seems more appropriate as it addresses the type error and
is more efficient.¹
The internal column names have been stripped of their leading
underscores to avoid being renamed.²
¹ https://stackoverflow.com/a/70227993
² "Notes" section in https://pandas.pydata.org/pandas-docs/version/2.3/reference/api/pandas.DataFrame.itertuples.html
|
This introduced new Mypy errors: The first 2 aren't necessary (Pyright infers that For now, I'll plan to add |
Errors for augur/validate_export.py:
Need type annotation for "seen" [var-annotated]
This is unnecessary – Pyright correctly infers that seen is ~TreeAttrs.
Errors for augur/filter/subsample.py:
"str" not callable [operator]
"bytes" not callable [operator]
"date" not callable [operator]
…
These are false positives – Pyright correctly infers that row is
_PandasNamedTuple, not any of the types reported by Mypy.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1922 +/- ##
==========================================
+ Coverage 74.15% 74.18% +0.02%
==========================================
Files 82 82
Lines 8986 8996 +10
Branches 1828 1828
==========================================
+ Hits 6664 6674 +10
Misses 2018 2018
Partials 304 304 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description of proposed changes
Enable
reportGeneralTypeIssuesand 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
#1917 (review) suggested adding type hints, and I figured this PR would make the hints more useful.
Checklist